Bill Wendling | ec45454 | 2013-01-28 21:55:20 +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 | // |
Bill Wendling | ec45454 | 2013-01-28 21:55:20 +0000 | [diff] [blame] | 10 | // \file |
| 11 | // \brief This file implements the Attribute, AttributeImpl, AttrBuilder, |
Bill Wendling | 6848e38 | 2012-12-19 22:42:22 +0000 | [diff] [blame] | 12 | // AttributeSetImpl, and AttributeSet classes. |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Attributes.h" |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 17 | #include "AttributeImpl.h" |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 18 | #include "LLVMContextImpl.h" |
Benjamin Kramer | 502b9e1 | 2014-04-12 16:15:53 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Type.h" |
Benjamin Kramer | 17388a6 | 2014-03-03 18:02:34 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Atomic.h" |
David Greene | f701473 | 2010-01-05 01:29:58 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ManagedStatic.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Mutex.h" |
Benjamin Kramer | 1a25d73 | 2009-08-23 11:37:21 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Bill Wendling | d2e493b | 2013-01-24 00:06:56 +0000 | [diff] [blame] | 27 | #include <algorithm> |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 30 | //===----------------------------------------------------------------------===// |
Bill Wendling | 7707c5a | 2013-01-29 00:48:16 +0000 | [diff] [blame] | 31 | // Attribute Construction Methods |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 32 | //===----------------------------------------------------------------------===// |
Chris Lattner | d0e1f10 | 2008-01-03 00:10:22 +0000 | [diff] [blame] | 33 | |
Matt Arsenault | e1cef6e | 2014-09-03 23:24:31 +0000 | [diff] [blame] | 34 | Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, |
| 35 | uint64_t Val) { |
| 36 | LLVMContextImpl *pImpl = Context.pImpl; |
| 37 | FoldingSetNodeID ID; |
| 38 | ID.AddInteger(Kind); |
Matt Arsenault | fb4308e | 2014-09-03 23:38:05 +0000 | [diff] [blame] | 39 | if (Val) ID.AddInteger(Val); |
Matt Arsenault | e1cef6e | 2014-09-03 23:24:31 +0000 | [diff] [blame] | 40 | |
| 41 | void *InsertPoint; |
| 42 | AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
| 43 | |
| 44 | if (!PA) { |
| 45 | // If we didn't find any existing attributes of the same shape then create a |
| 46 | // new one and insert it. |
Matt Arsenault | fb4308e | 2014-09-03 23:38:05 +0000 | [diff] [blame] | 47 | if (!Val) |
| 48 | PA = new EnumAttributeImpl(Kind); |
| 49 | else |
| 50 | PA = new IntAttributeImpl(Kind, Val); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 51 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 52 | } |
| 53 | |
| 54 | // Return the Attribute that we found or created. |
| 55 | return Attribute(PA); |
| 56 | } |
| 57 | |
| 58 | Attribute Attribute::get(LLVMContext &Context, StringRef Kind, StringRef Val) { |
| 59 | LLVMContextImpl *pImpl = Context.pImpl; |
| 60 | FoldingSetNodeID ID; |
| 61 | ID.AddString(Kind); |
| 62 | if (!Val.empty()) ID.AddString(Val); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 63 | |
| 64 | void *InsertPoint; |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 65 | AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 66 | |
| 67 | if (!PA) { |
| 68 | // If we didn't find any existing attributes of the same shape then create a |
| 69 | // new one and insert it. |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 70 | PA = new StringAttributeImpl(Kind, Val); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 71 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 72 | } |
| 73 | |
Bill Wendling | b9c5b1a | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 74 | // Return the Attribute that we found or created. |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 75 | return Attribute(PA); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Bill Wendling | 4bbe9db | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 78 | Attribute Attribute::getWithAlignment(LLVMContext &Context, uint64_t Align) { |
Bill Wendling | 1c7cc8a | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 79 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 80 | assert(Align <= 0x40000000 && "Alignment too large."); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 81 | return get(Context, Alignment, Align); |
Bill Wendling | 4bbe9db | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | Attribute Attribute::getWithStackAlignment(LLVMContext &Context, |
| 85 | uint64_t Align) { |
Bill Wendling | 1c7cc8a | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 86 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 87 | assert(Align <= 0x100 && "Alignment too large."); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 88 | return get(Context, StackAlignment, Align); |
Bill Wendling | 4bbe9db | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 91 | Attribute Attribute::getWithDereferenceableBytes(LLVMContext &Context, |
| 92 | uint64_t Bytes) { |
| 93 | assert(Bytes && "Bytes must be non-zero."); |
| 94 | return get(Context, Dereferenceable, Bytes); |
| 95 | } |
| 96 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 97 | Attribute Attribute::getWithDereferenceableOrNullBytes(LLVMContext &Context, |
| 98 | uint64_t Bytes) { |
| 99 | assert(Bytes && "Bytes must be non-zero."); |
| 100 | return get(Context, DereferenceableOrNull, Bytes); |
| 101 | } |
| 102 | |
Bill Wendling | 7707c5a | 2013-01-29 00:48:16 +0000 | [diff] [blame] | 103 | //===----------------------------------------------------------------------===// |
| 104 | // Attribute Accessor Methods |
| 105 | //===----------------------------------------------------------------------===// |
| 106 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 107 | bool Attribute::isEnumAttribute() const { |
| 108 | return pImpl && pImpl->isEnumAttribute(); |
| 109 | } |
| 110 | |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 111 | bool Attribute::isIntAttribute() const { |
| 112 | return pImpl && pImpl->isIntAttribute(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | bool Attribute::isStringAttribute() const { |
| 116 | return pImpl && pImpl->isStringAttribute(); |
| 117 | } |
| 118 | |
| 119 | Attribute::AttrKind Attribute::getKindAsEnum() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 120 | if (!pImpl) return None; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 121 | assert((isEnumAttribute() || isIntAttribute()) && |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 122 | "Invalid attribute type to get the kind as an enum!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 123 | return pImpl->getKindAsEnum(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | uint64_t Attribute::getValueAsInt() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 127 | if (!pImpl) return 0; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 128 | assert(isIntAttribute() && |
| 129 | "Expected the attribute to be an integer attribute!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 130 | return pImpl->getValueAsInt(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | StringRef Attribute::getKindAsString() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 134 | if (!pImpl) return StringRef(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 135 | assert(isStringAttribute() && |
| 136 | "Invalid attribute type to get the kind as a string!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 137 | return pImpl->getKindAsString(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | StringRef Attribute::getValueAsString() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 141 | if (!pImpl) return StringRef(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 142 | assert(isStringAttribute() && |
| 143 | "Invalid attribute type to get the value as a string!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 144 | return pImpl->getValueAsString(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Bill Wendling | ae89a0f | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 147 | bool Attribute::hasAttribute(AttrKind Kind) const { |
| 148 | return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None); |
| 149 | } |
| 150 | |
| 151 | bool Attribute::hasAttribute(StringRef Kind) const { |
| 152 | if (!isStringAttribute()) return false; |
| 153 | return pImpl && pImpl->hasAttribute(Kind); |
Bill Wendling | 03eefb3 | 2013-01-29 20:45:34 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 156 | /// This returns the alignment field of an attribute as a byte alignment value. |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 157 | unsigned Attribute::getAlignment() const { |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 158 | assert(hasAttribute(Attribute::Alignment) && |
| 159 | "Trying to get alignment from non-alignment attribute!"); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 160 | return pImpl->getValueAsInt(); |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /// This returns the stack alignment field of an attribute as a byte alignment |
| 164 | /// value. |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 165 | unsigned Attribute::getStackAlignment() const { |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 166 | assert(hasAttribute(Attribute::StackAlignment) && |
| 167 | "Trying to get alignment from non-alignment attribute!"); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 168 | return pImpl->getValueAsInt(); |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 171 | /// This returns the number of dereferenceable bytes. |
| 172 | uint64_t Attribute::getDereferenceableBytes() const { |
| 173 | assert(hasAttribute(Attribute::Dereferenceable) && |
| 174 | "Trying to get dereferenceable bytes from " |
| 175 | "non-dereferenceable attribute!"); |
| 176 | return pImpl->getValueAsInt(); |
| 177 | } |
| 178 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 179 | uint64_t Attribute::getDereferenceableOrNullBytes() const { |
| 180 | assert(hasAttribute(Attribute::DereferenceableOrNull) && |
| 181 | "Trying to get dereferenceable bytes from " |
| 182 | "non-dereferenceable attribute!"); |
| 183 | return pImpl->getValueAsInt(); |
| 184 | } |
| 185 | |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 186 | std::string Attribute::getAsString(bool InAttrGrp) const { |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 187 | if (!pImpl) return ""; |
| 188 | |
Kostya Serebryany | cf880b9 | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 189 | if (hasAttribute(Attribute::SanitizeAddress)) |
| 190 | return "sanitize_address"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 191 | if (hasAttribute(Attribute::AlwaysInline)) |
| 192 | return "alwaysinline"; |
Igor Laevsky | 39d662f | 2015-07-11 10:30:36 +0000 | [diff] [blame] | 193 | if (hasAttribute(Attribute::ArgMemOnly)) |
| 194 | return "argmemonly"; |
Michael Gottesman | 41748d7 | 2013-06-27 00:25:01 +0000 | [diff] [blame] | 195 | if (hasAttribute(Attribute::Builtin)) |
| 196 | return "builtin"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 197 | if (hasAttribute(Attribute::ByVal)) |
| 198 | return "byval"; |
Owen Anderson | 85fa7d5 | 2015-05-26 23:48:40 +0000 | [diff] [blame] | 199 | if (hasAttribute(Attribute::Convergent)) |
| 200 | return "convergent"; |
Reid Kleckner | a534a38 | 2013-12-19 02:14:12 +0000 | [diff] [blame] | 201 | if (hasAttribute(Attribute::InAlloca)) |
| 202 | return "inalloca"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 203 | if (hasAttribute(Attribute::InlineHint)) |
| 204 | return "inlinehint"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 205 | if (hasAttribute(Attribute::InReg)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 206 | return "inreg"; |
Tom Roeder | 44cb65f | 2014-06-05 19:29:43 +0000 | [diff] [blame] | 207 | if (hasAttribute(Attribute::JumpTable)) |
| 208 | return "jumptable"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 209 | if (hasAttribute(Attribute::MinSize)) |
| 210 | return "minsize"; |
| 211 | if (hasAttribute(Attribute::Naked)) |
| 212 | return "naked"; |
| 213 | if (hasAttribute(Attribute::Nest)) |
| 214 | return "nest"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 215 | if (hasAttribute(Attribute::NoAlias)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 216 | return "noalias"; |
Bill Wendling | 09bd1f7 | 2013-02-22 00:12:35 +0000 | [diff] [blame] | 217 | if (hasAttribute(Attribute::NoBuiltin)) |
| 218 | return "nobuiltin"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 219 | if (hasAttribute(Attribute::NoCapture)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 220 | return "nocapture"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 221 | if (hasAttribute(Attribute::NoDuplicate)) |
| 222 | return "noduplicate"; |
| 223 | if (hasAttribute(Attribute::NoImplicitFloat)) |
| 224 | return "noimplicitfloat"; |
| 225 | if (hasAttribute(Attribute::NoInline)) |
| 226 | return "noinline"; |
| 227 | if (hasAttribute(Attribute::NonLazyBind)) |
| 228 | return "nonlazybind"; |
Nick Lewycky | d52b152 | 2014-05-20 01:23:40 +0000 | [diff] [blame] | 229 | if (hasAttribute(Attribute::NonNull)) |
| 230 | return "nonnull"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 231 | if (hasAttribute(Attribute::NoRedZone)) |
| 232 | return "noredzone"; |
| 233 | if (hasAttribute(Attribute::NoReturn)) |
| 234 | return "noreturn"; |
James Molloy | e6f87ca | 2015-11-06 10:32:53 +0000 | [diff] [blame] | 235 | if (hasAttribute(Attribute::NoRecurse)) |
| 236 | return "norecurse"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 237 | if (hasAttribute(Attribute::NoUnwind)) |
| 238 | return "nounwind"; |
Andrea Di Biagio | 377496b | 2013-08-23 11:53:55 +0000 | [diff] [blame] | 239 | if (hasAttribute(Attribute::OptimizeNone)) |
| 240 | return "optnone"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 241 | if (hasAttribute(Attribute::OptimizeForSize)) |
| 242 | return "optsize"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 243 | if (hasAttribute(Attribute::ReadNone)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 244 | return "readnone"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 245 | if (hasAttribute(Attribute::ReadOnly)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 246 | return "readonly"; |
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 247 | if (hasAttribute(Attribute::Returned)) |
| 248 | return "returned"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 249 | if (hasAttribute(Attribute::ReturnsTwice)) |
| 250 | return "returns_twice"; |
| 251 | if (hasAttribute(Attribute::SExt)) |
| 252 | return "signext"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 253 | if (hasAttribute(Attribute::StackProtect)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 254 | return "ssp"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 255 | if (hasAttribute(Attribute::StackProtectReq)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 256 | return "sspreq"; |
Bill Wendling | d154e283 | 2013-01-23 06:41:41 +0000 | [diff] [blame] | 257 | if (hasAttribute(Attribute::StackProtectStrong)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 258 | return "sspstrong"; |
Peter Collingbourne | 82437bf | 2015-06-15 21:07:11 +0000 | [diff] [blame] | 259 | if (hasAttribute(Attribute::SafeStack)) |
| 260 | return "safestack"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 261 | if (hasAttribute(Attribute::StructRet)) |
| 262 | return "sret"; |
Kostya Serebryany | cf880b9 | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 263 | if (hasAttribute(Attribute::SanitizeThread)) |
| 264 | return "sanitize_thread"; |
| 265 | if (hasAttribute(Attribute::SanitizeMemory)) |
| 266 | return "sanitize_memory"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 267 | if (hasAttribute(Attribute::UWTable)) |
| 268 | return "uwtable"; |
| 269 | if (hasAttribute(Attribute::ZExt)) |
| 270 | return "zeroext"; |
Diego Novillo | c639953 | 2013-05-24 12:26:52 +0000 | [diff] [blame] | 271 | if (hasAttribute(Attribute::Cold)) |
| 272 | return "cold"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 273 | |
| 274 | // FIXME: These should be output like this: |
| 275 | // |
| 276 | // align=4 |
| 277 | // alignstack=8 |
| 278 | // |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 279 | if (hasAttribute(Attribute::Alignment)) { |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 280 | std::string Result; |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 281 | Result += "align"; |
| 282 | Result += (InAttrGrp) ? "=" : " "; |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 283 | Result += utostr(getValueAsInt()); |
| 284 | return Result; |
| 285 | } |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 286 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 287 | auto AttrWithBytesToString = [&](const char *Name) { |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 288 | std::string Result; |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 289 | Result += Name; |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 290 | if (InAttrGrp) { |
| 291 | Result += "="; |
| 292 | Result += utostr(getValueAsInt()); |
| 293 | } else { |
| 294 | Result += "("; |
| 295 | Result += utostr(getValueAsInt()); |
| 296 | Result += ")"; |
| 297 | } |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 298 | return Result; |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 299 | }; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 300 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 301 | if (hasAttribute(Attribute::StackAlignment)) |
| 302 | return AttrWithBytesToString("alignstack"); |
| 303 | |
| 304 | if (hasAttribute(Attribute::Dereferenceable)) |
| 305 | return AttrWithBytesToString("dereferenceable"); |
| 306 | |
| 307 | if (hasAttribute(Attribute::DereferenceableOrNull)) |
| 308 | return AttrWithBytesToString("dereferenceable_or_null"); |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 309 | |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 310 | // Convert target-dependent attributes to strings of the form: |
| 311 | // |
| 312 | // "kind" |
| 313 | // "kind" = "value" |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 314 | // |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 315 | if (isStringAttribute()) { |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 316 | std::string Result; |
Yaron Keren | 075759a | 2015-03-30 15:42:36 +0000 | [diff] [blame] | 317 | Result += (Twine('"') + getKindAsString() + Twine('"')).str(); |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 318 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 319 | StringRef Val = pImpl->getValueAsString(); |
| 320 | if (Val.empty()) return Result; |
Bill Wendling | 7a33f77 | 2013-02-01 22:32:30 +0000 | [diff] [blame] | 321 | |
Yaron Keren | 075759a | 2015-03-30 15:42:36 +0000 | [diff] [blame] | 322 | Result += ("=\"" + Val + Twine('"')).str(); |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 323 | return Result; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 324 | } |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 325 | |
| 326 | llvm_unreachable("Unknown attribute"); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 329 | bool Attribute::operator<(Attribute A) const { |
| 330 | if (!pImpl && !A.pImpl) return false; |
| 331 | if (!pImpl) return true; |
| 332 | if (!A.pImpl) return false; |
| 333 | return *pImpl < *A.pImpl; |
| 334 | } |
| 335 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 336 | //===----------------------------------------------------------------------===// |
| 337 | // AttributeImpl Definition |
| 338 | //===----------------------------------------------------------------------===// |
| 339 | |
Eric Christopher | 0eaa541 | 2014-07-02 22:05:40 +0000 | [diff] [blame] | 340 | // Pin the vtables to this file. |
Alexey Samsonov | 49109a2 | 2013-11-18 09:31:53 +0000 | [diff] [blame] | 341 | AttributeImpl::~AttributeImpl() {} |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 342 | void EnumAttributeImpl::anchor() {} |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 343 | void IntAttributeImpl::anchor() {} |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 344 | void StringAttributeImpl::anchor() {} |
Alexey Samsonov | 49109a2 | 2013-11-18 09:31:53 +0000 | [diff] [blame] | 345 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 346 | bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const { |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 347 | if (isStringAttribute()) return false; |
| 348 | return getKindAsEnum() == A; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 351 | bool AttributeImpl::hasAttribute(StringRef Kind) const { |
| 352 | if (!isStringAttribute()) return false; |
| 353 | return getKindAsString() == Kind; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 356 | Attribute::AttrKind AttributeImpl::getKindAsEnum() const { |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 357 | assert(isEnumAttribute() || isIntAttribute()); |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 358 | return static_cast<const EnumAttributeImpl *>(this)->getEnumKind(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 361 | uint64_t AttributeImpl::getValueAsInt() const { |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 362 | assert(isIntAttribute()); |
| 363 | return static_cast<const IntAttributeImpl *>(this)->getValue(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 366 | StringRef AttributeImpl::getKindAsString() const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 367 | assert(isStringAttribute()); |
| 368 | return static_cast<const StringAttributeImpl *>(this)->getStringKind(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 371 | StringRef AttributeImpl::getValueAsString() const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 372 | assert(isStringAttribute()); |
| 373 | return static_cast<const StringAttributeImpl *>(this)->getStringValue(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | bool AttributeImpl::operator<(const AttributeImpl &AI) const { |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 377 | // This sorts the attributes with Attribute::AttrKinds coming first (sorted |
| 378 | // relative to their enum value) and then strings. |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 379 | if (isEnumAttribute()) { |
| 380 | if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum(); |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 381 | if (AI.isIntAttribute()) return true; |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 382 | if (AI.isStringAttribute()) return true; |
| 383 | } |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 384 | |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 385 | if (isIntAttribute()) { |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 386 | if (AI.isEnumAttribute()) return false; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 387 | if (AI.isIntAttribute()) return getValueAsInt() < AI.getValueAsInt(); |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 388 | if (AI.isStringAttribute()) return true; |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 389 | } |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 390 | |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 391 | if (AI.isEnumAttribute()) return false; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 392 | if (AI.isIntAttribute()) return false; |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 393 | if (getKindAsString() == AI.getKindAsString()) |
| 394 | return getValueAsString() < AI.getValueAsString(); |
| 395 | return getKindAsString() < AI.getKindAsString(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 398 | uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) { |
| 399 | // FIXME: Remove this. |
| 400 | switch (Val) { |
| 401 | case Attribute::EndAttrKinds: |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 402 | llvm_unreachable("Synthetic enumerators which should never get here"); |
| 403 | |
| 404 | case Attribute::None: return 0; |
| 405 | case Attribute::ZExt: return 1 << 0; |
| 406 | case Attribute::SExt: return 1 << 1; |
| 407 | case Attribute::NoReturn: return 1 << 2; |
| 408 | case Attribute::InReg: return 1 << 3; |
| 409 | case Attribute::StructRet: return 1 << 4; |
| 410 | case Attribute::NoUnwind: return 1 << 5; |
| 411 | case Attribute::NoAlias: return 1 << 6; |
| 412 | case Attribute::ByVal: return 1 << 7; |
| 413 | case Attribute::Nest: return 1 << 8; |
| 414 | case Attribute::ReadNone: return 1 << 9; |
| 415 | case Attribute::ReadOnly: return 1 << 10; |
| 416 | case Attribute::NoInline: return 1 << 11; |
| 417 | case Attribute::AlwaysInline: return 1 << 12; |
| 418 | case Attribute::OptimizeForSize: return 1 << 13; |
| 419 | case Attribute::StackProtect: return 1 << 14; |
| 420 | case Attribute::StackProtectReq: return 1 << 15; |
| 421 | case Attribute::Alignment: return 31 << 16; |
| 422 | case Attribute::NoCapture: return 1 << 21; |
| 423 | case Attribute::NoRedZone: return 1 << 22; |
| 424 | case Attribute::NoImplicitFloat: return 1 << 23; |
| 425 | case Attribute::Naked: return 1 << 24; |
| 426 | case Attribute::InlineHint: return 1 << 25; |
| 427 | case Attribute::StackAlignment: return 7 << 26; |
| 428 | case Attribute::ReturnsTwice: return 1 << 29; |
| 429 | case Attribute::UWTable: return 1 << 30; |
| 430 | case Attribute::NonLazyBind: return 1U << 31; |
Kostya Serebryany | cf880b9 | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 431 | case Attribute::SanitizeAddress: return 1ULL << 32; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 432 | case Attribute::MinSize: return 1ULL << 33; |
| 433 | case Attribute::NoDuplicate: return 1ULL << 34; |
| 434 | case Attribute::StackProtectStrong: return 1ULL << 35; |
Kostya Serebryany | cf880b9 | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 435 | case Attribute::SanitizeThread: return 1ULL << 36; |
| 436 | case Attribute::SanitizeMemory: return 1ULL << 37; |
Bill Wendling | 7bfdfe7 | 2013-02-22 00:40:12 +0000 | [diff] [blame] | 437 | case Attribute::NoBuiltin: return 1ULL << 38; |
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 438 | case Attribute::Returned: return 1ULL << 39; |
Diego Novillo | c639953 | 2013-05-24 12:26:52 +0000 | [diff] [blame] | 439 | case Attribute::Cold: return 1ULL << 40; |
Michael Gottesman | 41748d7 | 2013-06-27 00:25:01 +0000 | [diff] [blame] | 440 | case Attribute::Builtin: return 1ULL << 41; |
Andrea Di Biagio | 377496b | 2013-08-23 11:53:55 +0000 | [diff] [blame] | 441 | case Attribute::OptimizeNone: return 1ULL << 42; |
Reid Kleckner | a534a38 | 2013-12-19 02:14:12 +0000 | [diff] [blame] | 442 | case Attribute::InAlloca: return 1ULL << 43; |
Nick Lewycky | d52b152 | 2014-05-20 01:23:40 +0000 | [diff] [blame] | 443 | case Attribute::NonNull: return 1ULL << 44; |
Tom Roeder | 44cb65f | 2014-06-05 19:29:43 +0000 | [diff] [blame] | 444 | case Attribute::JumpTable: return 1ULL << 45; |
Owen Anderson | 85fa7d5 | 2015-05-26 23:48:40 +0000 | [diff] [blame] | 445 | case Attribute::Convergent: return 1ULL << 46; |
Peter Collingbourne | 82437bf | 2015-06-15 21:07:11 +0000 | [diff] [blame] | 446 | case Attribute::SafeStack: return 1ULL << 47; |
James Molloy | e6f87ca | 2015-11-06 10:32:53 +0000 | [diff] [blame] | 447 | case Attribute::NoRecurse: return 1ULL << 48; |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 448 | case Attribute::Dereferenceable: |
| 449 | llvm_unreachable("dereferenceable attribute not supported in raw format"); |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 450 | break; |
| 451 | case Attribute::DereferenceableOrNull: |
| 452 | llvm_unreachable("dereferenceable_or_null attribute not supported in raw " |
| 453 | "format"); |
| 454 | break; |
Igor Laevsky | 39d662f | 2015-07-11 10:30:36 +0000 | [diff] [blame] | 455 | case Attribute::ArgMemOnly: |
| 456 | llvm_unreachable("argmemonly attribute not supported in raw format"); |
| 457 | break; |
Bill Wendling | 25342e1 | 2013-02-22 00:50:09 +0000 | [diff] [blame] | 458 | } |
| 459 | llvm_unreachable("Unsupported attribute type"); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | //===----------------------------------------------------------------------===// |
| 463 | // AttributeSetNode Definition |
| 464 | //===----------------------------------------------------------------------===// |
| 465 | |
| 466 | AttributeSetNode *AttributeSetNode::get(LLVMContext &C, |
| 467 | ArrayRef<Attribute> Attrs) { |
| 468 | if (Attrs.empty()) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 469 | return nullptr; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 470 | |
| 471 | // Otherwise, build a key to look up the existing attributes. |
| 472 | LLVMContextImpl *pImpl = C.pImpl; |
| 473 | FoldingSetNodeID ID; |
| 474 | |
| 475 | SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end()); |
Bill Wendling | 82c2ee6 | 2013-02-13 09:26:26 +0000 | [diff] [blame] | 476 | array_pod_sort(SortedAttrs.begin(), SortedAttrs.end()); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 477 | |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 478 | for (Attribute Attr : SortedAttrs) |
| 479 | Attr.Profile(ID); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 480 | |
| 481 | void *InsertPoint; |
| 482 | AttributeSetNode *PA = |
| 483 | pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint); |
| 484 | |
| 485 | // If we didn't find any existing attributes of the same shape then create a |
| 486 | // new one and insert it. |
| 487 | if (!PA) { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 488 | // Coallocate entries after the AttributeSetNode itself. |
James Y Knight | aa365b2 | 2015-08-05 22:57:34 +0000 | [diff] [blame] | 489 | void *Mem = ::operator new(totalSizeToAlloc<Attribute>(SortedAttrs.size())); |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 490 | PA = new (Mem) AttributeSetNode(SortedAttrs); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 491 | pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint); |
| 492 | } |
| 493 | |
| 494 | // Return the AttributesListNode that we found or created. |
| 495 | return PA; |
| 496 | } |
| 497 | |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 498 | bool AttributeSetNode::hasAttribute(Attribute::AttrKind Kind) const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 499 | for (iterator I = begin(), E = end(); I != E; ++I) |
NAKAMURA Takumi | b094439 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 500 | if (I->hasAttribute(Kind)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 501 | return true; |
| 502 | return false; |
| 503 | } |
| 504 | |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 505 | bool AttributeSetNode::hasAttribute(StringRef Kind) const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 506 | for (iterator I = begin(), E = end(); I != E; ++I) |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 507 | if (I->hasAttribute(Kind)) |
| 508 | return true; |
| 509 | return false; |
| 510 | } |
| 511 | |
| 512 | Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 513 | for (iterator I = begin(), E = end(); I != E; ++I) |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 514 | if (I->hasAttribute(Kind)) |
| 515 | return *I; |
| 516 | return Attribute(); |
| 517 | } |
| 518 | |
| 519 | Attribute AttributeSetNode::getAttribute(StringRef Kind) const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 520 | for (iterator I = begin(), E = end(); I != E; ++I) |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 521 | if (I->hasAttribute(Kind)) |
| 522 | return *I; |
| 523 | return Attribute(); |
| 524 | } |
| 525 | |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 526 | unsigned AttributeSetNode::getAlignment() const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 527 | for (iterator I = begin(), E = end(); I != E; ++I) |
NAKAMURA Takumi | b094439 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 528 | if (I->hasAttribute(Attribute::Alignment)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 529 | return I->getAlignment(); |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | unsigned AttributeSetNode::getStackAlignment() const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 534 | for (iterator I = begin(), E = end(); I != E; ++I) |
NAKAMURA Takumi | b094439 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 535 | if (I->hasAttribute(Attribute::StackAlignment)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 536 | return I->getStackAlignment(); |
| 537 | return 0; |
| 538 | } |
| 539 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 540 | uint64_t AttributeSetNode::getDereferenceableBytes() const { |
| 541 | for (iterator I = begin(), E = end(); I != E; ++I) |
| 542 | if (I->hasAttribute(Attribute::Dereferenceable)) |
| 543 | return I->getDereferenceableBytes(); |
| 544 | return 0; |
| 545 | } |
| 546 | |
Sanjoy Das | 06cf33f | 2015-05-06 17:41:54 +0000 | [diff] [blame] | 547 | uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { |
| 548 | for (iterator I = begin(), E = end(); I != E; ++I) |
| 549 | if (I->hasAttribute(Attribute::DereferenceableOrNull)) |
| 550 | return I->getDereferenceableOrNullBytes(); |
| 551 | return 0; |
| 552 | } |
| 553 | |
Rafael Espindola | cbf5a7a | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 554 | std::string AttributeSetNode::getAsString(bool InAttrGrp) const { |
Benjamin Kramer | 0baf8f4 | 2013-04-19 11:43:21 +0000 | [diff] [blame] | 555 | std::string Str; |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 556 | for (iterator I = begin(), E = end(); I != E; ++I) { |
| 557 | if (I != begin()) |
Rafael Espindola | cbf5a7a | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 558 | Str += ' '; |
| 559 | Str += I->getAsString(InAttrGrp); |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 560 | } |
| 561 | return Str; |
| 562 | } |
| 563 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 564 | //===----------------------------------------------------------------------===// |
| 565 | // AttributeSetImpl Definition |
| 566 | //===----------------------------------------------------------------------===// |
| 567 | |
Rafael Espindola | dd27530 | 2013-04-30 16:53:38 +0000 | [diff] [blame] | 568 | uint64_t AttributeSetImpl::Raw(unsigned Index) const { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 569 | for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) { |
| 570 | if (getSlotIndex(I) != Index) continue; |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 571 | const AttributeSetNode *ASN = getSlotNode(I); |
Bill Wendling | 9122618 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 572 | uint64_t Mask = 0; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 573 | |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 574 | for (AttributeSetNode::iterator II = ASN->begin(), |
Bill Wendling | 9122618 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 575 | IE = ASN->end(); II != IE; ++II) { |
| 576 | Attribute Attr = *II; |
Bill Wendling | d746e40 | 2013-02-10 23:18:05 +0000 | [diff] [blame] | 577 | |
| 578 | // This cannot handle string attributes. |
| 579 | if (Attr.isStringAttribute()) continue; |
| 580 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 581 | Attribute::AttrKind Kind = Attr.getKindAsEnum(); |
Bill Wendling | 9122618 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 582 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 583 | if (Kind == Attribute::Alignment) |
Bill Wendling | 9122618 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 584 | Mask |= (Log2_32(ASN->getAlignment()) + 1) << 16; |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 585 | else if (Kind == Attribute::StackAlignment) |
Bill Wendling | 9122618 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 586 | Mask |= (Log2_32(ASN->getStackAlignment()) + 1) << 26; |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 587 | else if (Kind == Attribute::Dereferenceable) |
| 588 | llvm_unreachable("dereferenceable not supported in bit mask"); |
Bill Wendling | 9122618 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 589 | else |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 590 | Mask |= AttributeImpl::getAttrMask(Kind); |
Bill Wendling | 9122618 | 2013-02-02 00:52:44 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | return Mask; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
Peter Collingbourne | abca2ec | 2013-08-02 22:34:30 +0000 | [diff] [blame] | 599 | void AttributeSetImpl::dump() const { |
| 600 | AttributeSet(const_cast<AttributeSetImpl *>(this)).dump(); |
| 601 | } |
| 602 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 603 | //===----------------------------------------------------------------------===// |
| 604 | // AttributeSet Construction and Mutation Methods |
| 605 | //===----------------------------------------------------------------------===// |
| 606 | |
Bill Wendling | 60011b8 | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 607 | AttributeSet |
| 608 | AttributeSet::getImpl(LLVMContext &C, |
| 609 | ArrayRef<std::pair<unsigned, AttributeSetNode*> > Attrs) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 610 | LLVMContextImpl *pImpl = C.pImpl; |
| 611 | FoldingSetNodeID ID; |
| 612 | AttributeSetImpl::Profile(ID, Attrs); |
| 613 | |
| 614 | void *InsertPoint; |
| 615 | AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint); |
| 616 | |
| 617 | // If we didn't find any existing attributes of the same shape then |
| 618 | // create a new one and insert it. |
| 619 | if (!PA) { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 620 | // Coallocate entries after the AttributeSetImpl itself. |
James Y Knight | aa365b2 | 2015-08-05 22:57:34 +0000 | [diff] [blame] | 621 | void *Mem = ::operator new( |
| 622 | AttributeSetImpl::totalSizeToAlloc<IndexAttrPair>(Attrs.size())); |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 623 | PA = new (Mem) AttributeSetImpl(C, Attrs); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 624 | pImpl->AttrsLists.InsertNode(PA, InsertPoint); |
| 625 | } |
| 626 | |
| 627 | // Return the AttributesList that we found or created. |
| 628 | return AttributeSet(PA); |
| 629 | } |
| 630 | |
| 631 | AttributeSet AttributeSet::get(LLVMContext &C, |
| 632 | ArrayRef<std::pair<unsigned, Attribute> > Attrs){ |
| 633 | // If there are no attributes then return a null AttributesList pointer. |
| 634 | if (Attrs.empty()) |
| 635 | return AttributeSet(); |
| 636 | |
| 637 | #ifndef NDEBUG |
| 638 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { |
| 639 | assert((!i || Attrs[i-1].first <= Attrs[i].first) && |
| 640 | "Misordered Attributes list!"); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 641 | assert(!Attrs[i].second.hasAttribute(Attribute::None) && |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 642 | "Pointless attribute!"); |
| 643 | } |
| 644 | #endif |
| 645 | |
| 646 | // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes |
| 647 | // list. |
| 648 | SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrPairVec; |
| 649 | for (ArrayRef<std::pair<unsigned, Attribute> >::iterator I = Attrs.begin(), |
| 650 | E = Attrs.end(); I != E; ) { |
| 651 | unsigned Index = I->first; |
| 652 | SmallVector<Attribute, 4> AttrVec; |
NAKAMURA Takumi | f05d2f2 | 2013-01-29 15:18:16 +0000 | [diff] [blame] | 653 | while (I != E && I->first == Index) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 654 | AttrVec.push_back(I->second); |
| 655 | ++I; |
| 656 | } |
| 657 | |
| 658 | AttrPairVec.push_back(std::make_pair(Index, |
| 659 | AttributeSetNode::get(C, AttrVec))); |
| 660 | } |
| 661 | |
| 662 | return getImpl(C, AttrPairVec); |
| 663 | } |
| 664 | |
| 665 | AttributeSet AttributeSet::get(LLVMContext &C, |
| 666 | ArrayRef<std::pair<unsigned, |
| 667 | AttributeSetNode*> > Attrs) { |
| 668 | // If there are no attributes then return a null AttributesList pointer. |
| 669 | if (Attrs.empty()) |
| 670 | return AttributeSet(); |
| 671 | |
| 672 | return getImpl(C, Attrs); |
| 673 | } |
| 674 | |
David Majnemer | cf63a79 | 2014-05-03 23:00:35 +0000 | [diff] [blame] | 675 | AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, |
| 676 | const AttrBuilder &B) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 677 | if (!B.hasAttributes()) |
| 678 | return AttributeSet(); |
Bill Wendling | f713481 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 679 | |
Bill Wendling | ae89a0f | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 680 | // Add target-independent attributes. |
Bill Wendling | f713481 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 681 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
Benjamin Kramer | 45e7d53 | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 682 | for (Attribute::AttrKind Kind = Attribute::None; |
Benjamin Kramer | 6f37dac | 2013-02-16 19:22:28 +0000 | [diff] [blame] | 683 | Kind != Attribute::EndAttrKinds; Kind = Attribute::AttrKind(Kind + 1)) { |
Benjamin Kramer | 45e7d53 | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 684 | if (!B.contains(Kind)) |
| 685 | continue; |
| 686 | |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 687 | Attribute Attr; |
| 688 | switch (Kind) { |
| 689 | case Attribute::Alignment: |
| 690 | Attr = Attribute::getWithAlignment(C, B.getAlignment()); |
| 691 | break; |
| 692 | case Attribute::StackAlignment: |
| 693 | Attr = Attribute::getWithStackAlignment(C, B.getStackAlignment()); |
| 694 | break; |
| 695 | case Attribute::Dereferenceable: |
| 696 | Attr = Attribute::getWithDereferenceableBytes( |
| 697 | C, B.getDereferenceableBytes()); |
| 698 | break; |
| 699 | case Attribute::DereferenceableOrNull: |
| 700 | Attr = Attribute::getWithDereferenceableOrNullBytes( |
| 701 | C, B.getDereferenceableOrNullBytes()); |
| 702 | break; |
| 703 | default: |
| 704 | Attr = Attribute::get(C, Kind); |
| 705 | } |
| 706 | Attrs.push_back(std::make_pair(Index, Attr)); |
Bill Wendling | f713481 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Bill Wendling | ae89a0f | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 709 | // Add target-dependent (string) attributes. |
David Majnemer | cf63a79 | 2014-05-03 23:00:35 +0000 | [diff] [blame] | 710 | for (const AttrBuilder::td_type &TDA : B.td_attrs()) |
| 711 | Attrs.push_back( |
| 712 | std::make_pair(Index, Attribute::get(C, TDA.first, TDA.second))); |
Bill Wendling | ae89a0f | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 713 | |
Bill Wendling | f713481 | 2013-01-29 01:02:03 +0000 | [diff] [blame] | 714 | return get(C, Attrs); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 717 | AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 718 | ArrayRef<Attribute::AttrKind> Kind) { |
| 719 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 720 | for (Attribute::AttrKind K : Kind) |
| 721 | Attrs.push_back(std::make_pair(Index, Attribute::get(C, K))); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 722 | return get(C, Attrs); |
| 723 | } |
| 724 | |
| 725 | AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) { |
| 726 | if (Attrs.empty()) return AttributeSet(); |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 727 | if (Attrs.size() == 1) return Attrs[0]; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 728 | |
| 729 | SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrNodeVec; |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 730 | AttributeSetImpl *A0 = Attrs[0].pImpl; |
| 731 | if (A0) |
| 732 | AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumAttributes())); |
| 733 | // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec |
| 734 | // ordered by index. Because we know that each list in Attrs is ordered by |
| 735 | // index we only need to merge each successive list in rather than doing a |
| 736 | // full sort. |
| 737 | for (unsigned I = 1, E = Attrs.size(); I != E; ++I) { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 738 | AttributeSetImpl *AS = Attrs[I].pImpl; |
| 739 | if (!AS) continue; |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 740 | SmallVector<std::pair<unsigned, AttributeSetNode *>, 8>::iterator |
| 741 | ANVI = AttrNodeVec.begin(), ANVE; |
James Y Knight | aa365b2 | 2015-08-05 22:57:34 +0000 | [diff] [blame] | 742 | for (const IndexAttrPair *AI = AS->getNode(0), |
| 743 | *AE = AS->getNode(AS->getNumAttributes()); |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 744 | AI != AE; ++AI) { |
| 745 | ANVE = AttrNodeVec.end(); |
| 746 | while (ANVI != ANVE && ANVI->first <= AI->first) |
| 747 | ++ANVI; |
| 748 | ANVI = AttrNodeVec.insert(ANVI, *AI) + 1; |
| 749 | } |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | return getImpl(C, AttrNodeVec); |
| 753 | } |
| 754 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 755 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 756 | Attribute::AttrKind Attr) const { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 757 | if (hasAttribute(Index, Attr)) return *this; |
| 758 | return addAttributes(C, Index, AttributeSet::get(C, Index, Attr)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 761 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, |
Reed Kotler | 795c7b4 | 2013-03-13 20:20:08 +0000 | [diff] [blame] | 762 | StringRef Kind) const { |
| 763 | llvm::AttrBuilder B; |
| 764 | B.addAttribute(Kind); |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 765 | return addAttributes(C, Index, AttributeSet::get(C, Index, B)); |
Reed Kotler | 795c7b4 | 2013-03-13 20:20:08 +0000 | [diff] [blame] | 766 | } |
| 767 | |
Bill Wendling | 3b2f610 | 2013-07-25 18:34:24 +0000 | [diff] [blame] | 768 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, |
| 769 | StringRef Kind, StringRef Value) const { |
| 770 | llvm::AttrBuilder B; |
| 771 | B.addAttribute(Kind, Value); |
| 772 | return addAttributes(C, Index, AttributeSet::get(C, Index, B)); |
| 773 | } |
| 774 | |
Akira Hatanaka | 237916b | 2015-12-02 06:58:49 +0000 | [diff] [blame] | 775 | AttributeSet AttributeSet::addAttribute(LLVMContext &C, |
| 776 | ArrayRef<unsigned> Indices, |
| 777 | Attribute A) const { |
| 778 | unsigned I = 0, E = pImpl ? pImpl->getNumAttributes() : 0; |
| 779 | auto IdxI = Indices.begin(), IdxE = Indices.end(); |
| 780 | SmallVector<AttributeSet, 4> AttrSet; |
| 781 | |
| 782 | while (I != E && IdxI != IdxE) { |
| 783 | if (getSlotIndex(I) < *IdxI) |
| 784 | AttrSet.emplace_back(getSlotAttributes(I++)); |
| 785 | else if (getSlotIndex(I) > *IdxI) |
| 786 | AttrSet.emplace_back(AttributeSet::get(C, std::make_pair(*IdxI++, A))); |
| 787 | else { |
| 788 | AttrBuilder B(getSlotAttributes(I), *IdxI); |
| 789 | B.addAttribute(A); |
| 790 | AttrSet.emplace_back(AttributeSet::get(C, *IdxI, B)); |
| 791 | ++I; |
| 792 | ++IdxI; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | while (I != E) |
| 797 | AttrSet.emplace_back(getSlotAttributes(I++)); |
| 798 | |
| 799 | while (IdxI != IdxE) |
| 800 | AttrSet.emplace_back(AttributeSet::get(C, std::make_pair(*IdxI++, A))); |
| 801 | |
| 802 | return get(C, AttrSet); |
| 803 | } |
| 804 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 805 | AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Index, |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 806 | AttributeSet Attrs) const { |
| 807 | if (!pImpl) return Attrs; |
| 808 | if (!Attrs.pImpl) return *this; |
| 809 | |
| 810 | #ifndef NDEBUG |
| 811 | // FIXME it is not obvious how this should work for alignment. For now, say |
| 812 | // we can't change a known alignment. |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 813 | unsigned OldAlign = getParamAlignment(Index); |
| 814 | unsigned NewAlign = Attrs.getParamAlignment(Index); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 815 | assert((!OldAlign || !NewAlign || OldAlign == NewAlign) && |
| 816 | "Attempt to change alignment!"); |
| 817 | #endif |
| 818 | |
| 819 | // Add the attribute slots before the one we're trying to add. |
| 820 | SmallVector<AttributeSet, 4> AttrSet; |
| 821 | uint64_t NumAttrs = pImpl->getNumAttributes(); |
| 822 | AttributeSet AS; |
| 823 | uint64_t LastIndex = 0; |
| 824 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 825 | if (getSlotIndex(I) >= Index) { |
| 826 | if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | LastIndex = I + 1; |
| 830 | AttrSet.push_back(getSlotAttributes(I)); |
| 831 | } |
| 832 | |
| 833 | // Now add the attribute into the correct slot. There may already be an |
| 834 | // AttributeSet there. |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 835 | AttrBuilder B(AS, Index); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 836 | |
| 837 | for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 838 | if (Attrs.getSlotIndex(I) == Index) { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 839 | for (AttributeSetImpl::iterator II = Attrs.pImpl->begin(I), |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 840 | IE = Attrs.pImpl->end(I); II != IE; ++II) |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 841 | B.addAttribute(*II); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 842 | break; |
| 843 | } |
| 844 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 845 | AttrSet.push_back(AttributeSet::get(C, Index, B)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 846 | |
| 847 | // Add the remaining attribute slots. |
| 848 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
| 849 | AttrSet.push_back(getSlotAttributes(I)); |
| 850 | |
| 851 | return get(C, AttrSet); |
| 852 | } |
| 853 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 854 | AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index, |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 855 | Attribute::AttrKind Attr) const { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 856 | if (!hasAttribute(Index, Attr)) return *this; |
| 857 | return removeAttributes(C, Index, AttributeSet::get(C, Index, Attr)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 860 | AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index, |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 861 | AttributeSet Attrs) const { |
| 862 | if (!pImpl) return AttributeSet(); |
| 863 | if (!Attrs.pImpl) return *this; |
| 864 | |
Pete Cooper | 67cf9a7 | 2015-11-19 05:56:52 +0000 | [diff] [blame] | 865 | // FIXME it is not obvious how this should work for alignment. |
| 866 | // For now, say we can't pass in alignment, which no current use does. |
| 867 | assert(!Attrs.hasAttribute(Index, Attribute::Alignment) && |
| 868 | "Attempt to change alignment!"); |
| 869 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 870 | // Add the attribute slots before the one we're trying to add. |
| 871 | SmallVector<AttributeSet, 4> AttrSet; |
| 872 | uint64_t NumAttrs = pImpl->getNumAttributes(); |
| 873 | AttributeSet AS; |
| 874 | uint64_t LastIndex = 0; |
| 875 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 876 | if (getSlotIndex(I) >= Index) { |
| 877 | if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 878 | break; |
| 879 | } |
| 880 | LastIndex = I + 1; |
| 881 | AttrSet.push_back(getSlotAttributes(I)); |
| 882 | } |
| 883 | |
Bill Wendling | d219675 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 884 | // Now remove the attribute from the correct slot. There may already be an |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 885 | // AttributeSet there. |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 886 | AttrBuilder B(AS, Index); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 887 | |
| 888 | for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 889 | if (Attrs.getSlotIndex(I) == Index) { |
| 890 | B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Index); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 891 | break; |
| 892 | } |
| 893 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 894 | AttrSet.push_back(AttributeSet::get(C, Index, B)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 895 | |
| 896 | // Add the remaining attribute slots. |
| 897 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
| 898 | AttrSet.push_back(getSlotAttributes(I)); |
| 899 | |
| 900 | return get(C, AttrSet); |
| 901 | } |
| 902 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 903 | AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index, |
| 904 | const AttrBuilder &Attrs) const { |
| 905 | if (!pImpl) return AttributeSet(); |
| 906 | |
| 907 | // FIXME it is not obvious how this should work for alignment. |
| 908 | // For now, say we can't pass in alignment, which no current use does. |
| 909 | assert(!Attrs.hasAlignmentAttr() && "Attempt to change alignment!"); |
| 910 | |
| 911 | // Add the attribute slots before the one we're trying to add. |
| 912 | SmallVector<AttributeSet, 4> AttrSet; |
| 913 | uint64_t NumAttrs = pImpl->getNumAttributes(); |
| 914 | AttributeSet AS; |
| 915 | uint64_t LastIndex = 0; |
| 916 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
| 917 | if (getSlotIndex(I) >= Index) { |
| 918 | if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++); |
| 919 | break; |
| 920 | } |
| 921 | LastIndex = I + 1; |
| 922 | AttrSet.push_back(getSlotAttributes(I)); |
| 923 | } |
| 924 | |
| 925 | // Now remove the attribute from the correct slot. There may already be an |
| 926 | // AttributeSet there. |
| 927 | AttrBuilder B(AS, Index); |
| 928 | B.remove(Attrs); |
| 929 | |
| 930 | AttrSet.push_back(AttributeSet::get(C, Index, B)); |
| 931 | |
| 932 | // Add the remaining attribute slots. |
| 933 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
| 934 | AttrSet.push_back(getSlotAttributes(I)); |
| 935 | |
| 936 | return get(C, AttrSet); |
| 937 | } |
| 938 | |
Ramkumar Ramachandra | 8fcb498 | 2015-02-14 19:37:54 +0000 | [diff] [blame] | 939 | AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index, |
| 940 | uint64_t Bytes) const { |
| 941 | llvm::AttrBuilder B; |
| 942 | B.addDereferenceableAttr(Bytes); |
| 943 | return addAttributes(C, Index, AttributeSet::get(C, Index, B)); |
| 944 | } |
| 945 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 946 | AttributeSet AttributeSet::addDereferenceableOrNullAttr(LLVMContext &C, |
| 947 | unsigned Index, |
| 948 | uint64_t Bytes) const { |
| 949 | llvm::AttrBuilder B; |
| 950 | B.addDereferenceableOrNullAttr(Bytes); |
| 951 | return addAttributes(C, Index, AttributeSet::get(C, Index, B)); |
| 952 | } |
| 953 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 954 | //===----------------------------------------------------------------------===// |
| 955 | // AttributeSet Accessor Methods |
| 956 | //===----------------------------------------------------------------------===// |
| 957 | |
Bill Wendling | 5d020a3 | 2013-02-10 05:00:40 +0000 | [diff] [blame] | 958 | LLVMContext &AttributeSet::getContext() const { |
| 959 | return pImpl->getContext(); |
| 960 | } |
| 961 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 962 | AttributeSet AttributeSet::getParamAttributes(unsigned Index) const { |
| 963 | return pImpl && hasAttributes(Index) ? |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 964 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 965 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 966 | std::make_pair(Index, getAttributes(Index)))) : |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 967 | AttributeSet(); |
| 968 | } |
| 969 | |
| 970 | AttributeSet AttributeSet::getRetAttributes() const { |
| 971 | return pImpl && hasAttributes(ReturnIndex) ? |
| 972 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 973 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 974 | std::make_pair(ReturnIndex, |
| 975 | getAttributes(ReturnIndex)))) : |
| 976 | AttributeSet(); |
| 977 | } |
| 978 | |
| 979 | AttributeSet AttributeSet::getFnAttributes() const { |
| 980 | return pImpl && hasAttributes(FunctionIndex) ? |
| 981 | AttributeSet::get(pImpl->getContext(), |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 982 | ArrayRef<std::pair<unsigned, AttributeSetNode*> >( |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 983 | std::make_pair(FunctionIndex, |
| 984 | getAttributes(FunctionIndex)))) : |
| 985 | AttributeSet(); |
| 986 | } |
| 987 | |
| 988 | bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{ |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 989 | AttributeSetNode *ASN = getAttributes(Index); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 990 | return ASN && ASN->hasAttribute(Kind); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 993 | bool AttributeSet::hasAttribute(unsigned Index, StringRef Kind) const { |
| 994 | AttributeSetNode *ASN = getAttributes(Index); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 995 | return ASN && ASN->hasAttribute(Kind); |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 998 | bool AttributeSet::hasAttributes(unsigned Index) const { |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 999 | AttributeSetNode *ASN = getAttributes(Index); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 1000 | return ASN && ASN->hasAttributes(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | /// \brief Return true if the specified attribute is set for at least one |
| 1004 | /// parameter or for the return value. |
| 1005 | bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 1006 | if (!pImpl) return false; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1007 | |
| 1008 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 1009 | for (AttributeSetImpl::iterator II = pImpl->begin(I), |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1010 | IE = pImpl->end(I); II != IE; ++II) |
NAKAMURA Takumi | b094439 | 2013-01-31 03:47:28 +0000 | [diff] [blame] | 1011 | if (II->hasAttribute(Attr)) |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1012 | return true; |
| 1013 | |
| 1014 | return false; |
| 1015 | } |
| 1016 | |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 1017 | Attribute AttributeSet::getAttribute(unsigned Index, |
| 1018 | Attribute::AttrKind Kind) const { |
| 1019 | AttributeSetNode *ASN = getAttributes(Index); |
| 1020 | return ASN ? ASN->getAttribute(Kind) : Attribute(); |
| 1021 | } |
| 1022 | |
| 1023 | Attribute AttributeSet::getAttribute(unsigned Index, |
| 1024 | StringRef Kind) const { |
| 1025 | AttributeSetNode *ASN = getAttributes(Index); |
| 1026 | return ASN ? ASN->getAttribute(Kind) : Attribute(); |
| 1027 | } |
| 1028 | |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 1029 | unsigned AttributeSet::getParamAlignment(unsigned Index) const { |
| 1030 | AttributeSetNode *ASN = getAttributes(Index); |
| 1031 | return ASN ? ASN->getAlignment() : 0; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | unsigned AttributeSet::getStackAlignment(unsigned Index) const { |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 1035 | AttributeSetNode *ASN = getAttributes(Index); |
| 1036 | return ASN ? ASN->getStackAlignment() : 0; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1039 | uint64_t AttributeSet::getDereferenceableBytes(unsigned Index) const { |
| 1040 | AttributeSetNode *ASN = getAttributes(Index); |
| 1041 | return ASN ? ASN->getDereferenceableBytes() : 0; |
| 1042 | } |
| 1043 | |
Sanjoy Das | 06cf33f | 2015-05-06 17:41:54 +0000 | [diff] [blame] | 1044 | uint64_t AttributeSet::getDereferenceableOrNullBytes(unsigned Index) const { |
| 1045 | AttributeSetNode *ASN = getAttributes(Index); |
| 1046 | return ASN ? ASN->getDereferenceableOrNullBytes() : 0; |
| 1047 | } |
| 1048 | |
Rafael Espindola | cbf5a7a | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 1049 | std::string AttributeSet::getAsString(unsigned Index, |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 1050 | bool InAttrGrp) const { |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 1051 | AttributeSetNode *ASN = getAttributes(Index); |
Rafael Espindola | cbf5a7a | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 1052 | return ASN ? ASN->getAsString(InAttrGrp) : std::string(""); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | /// \brief The attributes for the specified index are returned. |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1056 | AttributeSetNode *AttributeSet::getAttributes(unsigned Index) const { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 1057 | if (!pImpl) return nullptr; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1058 | |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 1059 | // Loop through to find the attribute node we want. |
| 1060 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1061 | if (pImpl->getSlotIndex(I) == Index) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 1062 | return pImpl->getSlotNode(I); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1063 | |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 1064 | return nullptr; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1067 | AttributeSet::iterator AttributeSet::begin(unsigned Slot) const { |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1068 | if (!pImpl) |
| 1069 | return ArrayRef<Attribute>().begin(); |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1070 | return pImpl->begin(Slot); |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1073 | AttributeSet::iterator AttributeSet::end(unsigned Slot) const { |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1074 | if (!pImpl) |
| 1075 | return ArrayRef<Attribute>().end(); |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1076 | return pImpl->end(Slot); |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1079 | //===----------------------------------------------------------------------===// |
| 1080 | // AttributeSet Introspection Methods |
| 1081 | //===----------------------------------------------------------------------===// |
| 1082 | |
| 1083 | /// \brief Return the number of slots used in this attribute list. This is the |
| 1084 | /// number of arguments that have an attribute set on them (including the |
| 1085 | /// function itself). |
| 1086 | unsigned AttributeSet::getNumSlots() const { |
| 1087 | return pImpl ? pImpl->getNumAttributes() : 0; |
| 1088 | } |
| 1089 | |
Rafael Espindola | dd27530 | 2013-04-30 16:53:38 +0000 | [diff] [blame] | 1090 | unsigned AttributeSet::getSlotIndex(unsigned Slot) const { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1091 | assert(pImpl && Slot < pImpl->getNumAttributes() && |
| 1092 | "Slot # out of range!"); |
| 1093 | return pImpl->getSlotIndex(Slot); |
| 1094 | } |
| 1095 | |
| 1096 | AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const { |
| 1097 | assert(pImpl && Slot < pImpl->getNumAttributes() && |
| 1098 | "Slot # out of range!"); |
| 1099 | return pImpl->getSlotAttributes(Slot); |
| 1100 | } |
| 1101 | |
| 1102 | uint64_t AttributeSet::Raw(unsigned Index) const { |
| 1103 | // FIXME: Remove this. |
| 1104 | return pImpl ? pImpl->Raw(Index) : 0; |
| 1105 | } |
| 1106 | |
| 1107 | void AttributeSet::dump() const { |
| 1108 | dbgs() << "PAL[\n"; |
| 1109 | |
| 1110 | for (unsigned i = 0, e = getNumSlots(); i < e; ++i) { |
| 1111 | uint64_t Index = getSlotIndex(i); |
| 1112 | dbgs() << " { "; |
| 1113 | if (Index == ~0U) |
| 1114 | dbgs() << "~0U"; |
| 1115 | else |
| 1116 | dbgs() << Index; |
| 1117 | dbgs() << " => " << getAsString(Index) << " }\n"; |
| 1118 | } |
| 1119 | |
| 1120 | dbgs() << "]\n"; |
| 1121 | } |
| 1122 | |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1123 | //===----------------------------------------------------------------------===// |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1124 | // AttrBuilder Method Implementations |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1125 | //===----------------------------------------------------------------------===// |
| 1126 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1127 | AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index) |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1128 | : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0), |
| 1129 | DerefOrNullBytes(0) { |
Bill Wendling | 56b0b2a | 2013-01-27 21:23:46 +0000 | [diff] [blame] | 1130 | AttributeSetImpl *pImpl = AS.pImpl; |
Bill Wendling | 096f544 | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 1131 | if (!pImpl) return; |
| 1132 | |
Bill Wendling | 9eb689c | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 1133 | for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1134 | if (pImpl->getSlotIndex(I) != Index) continue; |
Bill Wendling | 096f544 | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 1135 | |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 1136 | for (AttributeSetImpl::iterator II = pImpl->begin(I), |
Bill Wendling | 9eb689c | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 1137 | IE = pImpl->end(I); II != IE; ++II) |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1138 | addAttribute(*II); |
Bill Wendling | 9eb689c | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 1139 | |
| 1140 | break; |
| 1141 | } |
Bill Wendling | 096f544 | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1144 | void AttrBuilder::clear() { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1145 | Attrs.reset(); |
Sanjoy Das | 88d0fde | 2015-09-03 22:27:42 +0000 | [diff] [blame] | 1146 | TargetDepAttrs.clear(); |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1147 | Alignment = StackAlignment = DerefBytes = DerefOrNullBytes = 0; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1151 | assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!"); |
Bill Wendling | 1c7cc8a | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 1152 | assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment && |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1153 | Val != Attribute::Dereferenceable && |
| 1154 | "Adding integer attribute without adding a value!"); |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1155 | Attrs[Val] = true; |
Bill Wendling | 7c04e04 | 2012-10-09 19:01:18 +0000 | [diff] [blame] | 1156 | return *this; |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1159 | AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) { |
Bill Wendling | 0a43730 | 2013-02-10 10:13:23 +0000 | [diff] [blame] | 1160 | if (Attr.isStringAttribute()) { |
| 1161 | addAttribute(Attr.getKindAsString(), Attr.getValueAsString()); |
| 1162 | return *this; |
| 1163 | } |
| 1164 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 1165 | Attribute::AttrKind Kind = Attr.getKindAsEnum(); |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1166 | Attrs[Kind] = true; |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1167 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 1168 | if (Kind == Attribute::Alignment) |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1169 | Alignment = Attr.getAlignment(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 1170 | else if (Kind == Attribute::StackAlignment) |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1171 | StackAlignment = Attr.getStackAlignment(); |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1172 | else if (Kind == Attribute::Dereferenceable) |
| 1173 | DerefBytes = Attr.getDereferenceableBytes(); |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1174 | else if (Kind == Attribute::DereferenceableOrNull) |
| 1175 | DerefOrNullBytes = Attr.getDereferenceableOrNullBytes(); |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1176 | return *this; |
| 1177 | } |
| 1178 | |
Bill Wendling | b9c5b1a | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 1179 | AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) { |
| 1180 | TargetDepAttrs[A] = V; |
| 1181 | return *this; |
| 1182 | } |
| 1183 | |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1184 | AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1185 | assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!"); |
| 1186 | Attrs[Val] = false; |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1187 | |
| 1188 | if (Val == Attribute::Alignment) |
| 1189 | Alignment = 0; |
| 1190 | else if (Val == Attribute::StackAlignment) |
| 1191 | StackAlignment = 0; |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1192 | else if (Val == Attribute::Dereferenceable) |
| 1193 | DerefBytes = 0; |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1194 | else if (Val == Attribute::DereferenceableOrNull) |
| 1195 | DerefOrNullBytes = 0; |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1196 | |
| 1197 | return *this; |
| 1198 | } |
| 1199 | |
Bill Wendling | d219675 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 1200 | AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1201 | unsigned Slot = ~0U; |
Bill Wendling | f1c94e3 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1202 | for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I) |
| 1203 | if (A.getSlotIndex(I) == Index) { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1204 | Slot = I; |
Bill Wendling | f1c94e3 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1205 | break; |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1206 | } |
Bill Wendling | f1c94e3 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1207 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1208 | assert(Slot != ~0U && "Couldn't find index in AttributeSet!"); |
Bill Wendling | f1c94e3 | 2013-02-01 00:13:50 +0000 | [diff] [blame] | 1209 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1210 | for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) { |
Bill Wendling | 7cde51d | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1211 | Attribute Attr = *I; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 1212 | if (Attr.isEnumAttribute() || Attr.isIntAttribute()) { |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 1213 | removeAttribute(Attr.getKindAsEnum()); |
Bill Wendling | 7cde51d | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1214 | } else { |
| 1215 | assert(Attr.isStringAttribute() && "Invalid attribute type!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 1216 | removeAttribute(Attr.getKindAsString()); |
Bill Wendling | 7cde51d | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1217 | } |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | return *this; |
| 1221 | } |
| 1222 | |
Bill Wendling | b9c5b1a | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 1223 | AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { |
| 1224 | std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A); |
| 1225 | if (I != TargetDepAttrs.end()) |
| 1226 | TargetDepAttrs.erase(I); |
| 1227 | return *this; |
| 1228 | } |
| 1229 | |
Bill Wendling | 50d2784 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1230 | AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) { |
Bill Wendling | abd5ba2 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 1231 | if (Align == 0) return *this; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1232 | |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1233 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 1234 | assert(Align <= 0x40000000 && "Alignment too large."); |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1235 | |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1236 | Attrs[Attribute::Alignment] = true; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1237 | Alignment = Align; |
Bill Wendling | abd5ba2 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 1238 | return *this; |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1241 | AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) { |
| 1242 | // Default alignment, allow the target to define how to align it. |
| 1243 | if (Align == 0) return *this; |
| 1244 | |
| 1245 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 1246 | assert(Align <= 0x100 && "Alignment too large."); |
| 1247 | |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1248 | Attrs[Attribute::StackAlignment] = true; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1249 | StackAlignment = Align; |
| 1250 | return *this; |
| 1251 | } |
| 1252 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1253 | AttrBuilder &AttrBuilder::addDereferenceableAttr(uint64_t Bytes) { |
| 1254 | if (Bytes == 0) return *this; |
| 1255 | |
| 1256 | Attrs[Attribute::Dereferenceable] = true; |
| 1257 | DerefBytes = Bytes; |
| 1258 | return *this; |
| 1259 | } |
| 1260 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1261 | AttrBuilder &AttrBuilder::addDereferenceableOrNullAttr(uint64_t Bytes) { |
| 1262 | if (Bytes == 0) |
| 1263 | return *this; |
| 1264 | |
| 1265 | Attrs[Attribute::DereferenceableOrNull] = true; |
| 1266 | DerefOrNullBytes = Bytes; |
| 1267 | return *this; |
| 1268 | } |
| 1269 | |
Bill Wendling | e261492 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1270 | AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { |
| 1271 | // FIXME: What if both have alignments, but they don't match?! |
| 1272 | if (!Alignment) |
| 1273 | Alignment = B.Alignment; |
| 1274 | |
| 1275 | if (!StackAlignment) |
| 1276 | StackAlignment = B.StackAlignment; |
| 1277 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1278 | if (!DerefBytes) |
| 1279 | DerefBytes = B.DerefBytes; |
| 1280 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1281 | if (!DerefOrNullBytes) |
| 1282 | DerefOrNullBytes = B.DerefOrNullBytes; |
| 1283 | |
Benjamin Kramer | 45e7d53 | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 1284 | Attrs |= B.Attrs; |
Bill Wendling | e261492 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1285 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1286 | for (auto I : B.td_attrs()) |
| 1287 | TargetDepAttrs[I.first] = I.second; |
Bill Wendling | e261492 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1288 | |
| 1289 | return *this; |
| 1290 | } |
| 1291 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1292 | AttrBuilder &AttrBuilder::remove(const AttrBuilder &B) { |
| 1293 | // FIXME: What if both have alignments, but they don't match?! |
| 1294 | if (B.Alignment) |
| 1295 | Alignment = 0; |
| 1296 | |
| 1297 | if (B.StackAlignment) |
| 1298 | StackAlignment = 0; |
| 1299 | |
| 1300 | if (B.DerefBytes) |
| 1301 | DerefBytes = 0; |
| 1302 | |
| 1303 | if (B.DerefOrNullBytes) |
| 1304 | DerefOrNullBytes = 0; |
| 1305 | |
| 1306 | Attrs &= ~B.Attrs; |
| 1307 | |
| 1308 | for (auto I : B.td_attrs()) |
| 1309 | TargetDepAttrs.erase(I.first); |
| 1310 | |
| 1311 | return *this; |
| 1312 | } |
| 1313 | |
| 1314 | bool AttrBuilder::overlaps(const AttrBuilder &B) const { |
| 1315 | // First check if any of the target independent attributes overlap. |
| 1316 | if ((Attrs & B.Attrs).any()) |
| 1317 | return true; |
| 1318 | |
| 1319 | // Then check if any target dependent ones do. |
| 1320 | for (auto I : td_attrs()) |
| 1321 | if (B.contains(I.first)) |
| 1322 | return true; |
| 1323 | |
| 1324 | return false; |
| 1325 | } |
| 1326 | |
Bill Wendling | 4b00144 | 2013-02-06 01:33:42 +0000 | [diff] [blame] | 1327 | bool AttrBuilder::contains(StringRef A) const { |
| 1328 | return TargetDepAttrs.find(A) != TargetDepAttrs.end(); |
| 1329 | } |
| 1330 | |
Bill Wendling | 50d2784 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1331 | bool AttrBuilder::hasAttributes() const { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1332 | return !Attrs.none() || !TargetDepAttrs.empty(); |
Bill Wendling | c6daefa | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 1333 | } |
Bill Wendling | 9ac69f9 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 1334 | |
Bill Wendling | d219675 | 2013-01-30 23:07:40 +0000 | [diff] [blame] | 1335 | bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1336 | unsigned Slot = ~0U; |
Bill Wendling | 9ca01da | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1337 | for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I) |
| 1338 | if (A.getSlotIndex(I) == Index) { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1339 | Slot = I; |
Bill Wendling | 9ca01da | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1340 | break; |
| 1341 | } |
| 1342 | |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1343 | assert(Slot != ~0U && "Couldn't find the index!"); |
Bill Wendling | 9ca01da | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1344 | |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame^] | 1345 | for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) { |
Bill Wendling | 7cde51d | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1346 | Attribute Attr = *I; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 1347 | if (Attr.isEnumAttribute() || Attr.isIntAttribute()) { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1348 | if (Attrs[I->getKindAsEnum()]) |
Bill Wendling | 7cde51d | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1349 | return true; |
| 1350 | } else { |
| 1351 | assert(Attr.isStringAttribute() && "Invalid attribute kind!"); |
| 1352 | return TargetDepAttrs.find(Attr.getKindAsString())!=TargetDepAttrs.end(); |
| 1353 | } |
| 1354 | } |
Bill Wendling | 9ca01da | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1355 | |
| 1356 | return false; |
Bill Wendling | 70f3917 | 2012-10-09 00:01:21 +0000 | [diff] [blame] | 1357 | } |
Bill Wendling | 9ac69f9 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 1358 | |
Bill Wendling | 50d2784 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1359 | bool AttrBuilder::hasAlignmentAttr() const { |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1360 | return Alignment != 0; |
Bill Wendling | c6daefa | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1363 | bool AttrBuilder::operator==(const AttrBuilder &B) { |
Benjamin Kramer | 45e7d53 | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 1364 | if (Attrs != B.Attrs) |
| 1365 | return false; |
Bill Wendling | 4b00144 | 2013-02-06 01:33:42 +0000 | [diff] [blame] | 1366 | |
| 1367 | for (td_const_iterator I = TargetDepAttrs.begin(), |
| 1368 | E = TargetDepAttrs.end(); I != E; ++I) |
| 1369 | if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end()) |
| 1370 | return false; |
| 1371 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1372 | return Alignment == B.Alignment && StackAlignment == B.StackAlignment && |
| 1373 | DerefBytes == B.DerefBytes; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) { |
Bill Wendling | 56aeccc | 2013-02-04 23:32:23 +0000 | [diff] [blame] | 1377 | // FIXME: Remove this in 4.0. |
Bill Wendling | 60011b8 | 2013-01-29 01:43:29 +0000 | [diff] [blame] | 1378 | if (!Val) return *this; |
| 1379 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1380 | for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; |
| 1381 | I = Attribute::AttrKind(I + 1)) { |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1382 | if (I == Attribute::Dereferenceable || |
Igor Laevsky | 39d662f | 2015-07-11 10:30:36 +0000 | [diff] [blame] | 1383 | I == Attribute::DereferenceableOrNull || |
| 1384 | I == Attribute::ArgMemOnly) |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1385 | continue; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1386 | if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1387 | Attrs[I] = true; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1388 | |
| 1389 | if (I == Attribute::Alignment) |
| 1390 | Alignment = 1ULL << ((A >> 16) - 1); |
| 1391 | else if (I == Attribute::StackAlignment) |
| 1392 | StackAlignment = 1ULL << ((A >> 26)-1); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | return *this; |
| 1397 | } |
| 1398 | |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1399 | //===----------------------------------------------------------------------===// |
| 1400 | // AttributeFuncs Function Defintions |
| 1401 | //===----------------------------------------------------------------------===// |
| 1402 | |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 1403 | /// \brief Which attributes cannot be applied to a type. |
Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 1404 | AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) { |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1405 | AttrBuilder Incompatible; |
| 1406 | |
| 1407 | if (!Ty->isIntegerTy()) |
| 1408 | // Attribute that only apply to integers. |
| 1409 | Incompatible.addAttribute(Attribute::SExt) |
| 1410 | .addAttribute(Attribute::ZExt); |
| 1411 | |
| 1412 | if (!Ty->isPointerTy()) |
| 1413 | // Attribute that only apply to pointers. |
| 1414 | Incompatible.addAttribute(Attribute::ByVal) |
| 1415 | .addAttribute(Attribute::Nest) |
| 1416 | .addAttribute(Attribute::NoAlias) |
| 1417 | .addAttribute(Attribute::NoCapture) |
Nick Lewycky | d52b152 | 2014-05-20 01:23:40 +0000 | [diff] [blame] | 1418 | .addAttribute(Attribute::NonNull) |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1419 | .addDereferenceableAttr(1) // the int here is ignored |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1420 | .addDereferenceableOrNullAttr(1) // the int here is ignored |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 1421 | .addAttribute(Attribute::ReadNone) |
| 1422 | .addAttribute(Attribute::ReadOnly) |
Reid Kleckner | a534a38 | 2013-12-19 02:14:12 +0000 | [diff] [blame] | 1423 | .addAttribute(Attribute::StructRet) |
| 1424 | .addAttribute(Attribute::InAlloca); |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1425 | |
Pete Cooper | 2777d887 | 2015-05-06 23:19:56 +0000 | [diff] [blame] | 1426 | return Incompatible; |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1427 | } |