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