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