Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +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, |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 12 | // AttributeListImpl, and AttributeList classes. |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 16 | #include "AttributeImpl.h" |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 17 | #include "LLVMContextImpl.h" |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/ArrayRef.h" |
| 19 | #include "llvm/ADT/FoldingSet.h" |
| 20 | #include "llvm/ADT/Optional.h" |
| 21 | #include "llvm/ADT/SmallVector.h" |
Benjamin Kramer | 502b9e1 | 2014-04-12 16:15:53 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringRef.h" |
| 25 | #include "llvm/ADT/Twine.h" |
| 26 | #include "llvm/IR/Attributes.h" |
| 27 | #include "llvm/IR/Function.h" |
| 28 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 29 | #include "llvm/IR/Type.h" |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Compiler.h" |
David Greene | f701473 | 2010-01-05 01:29:58 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Debug.h" |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 32 | #include "llvm/Support/ErrorHandling.h" |
| 33 | #include "llvm/Support/MathExtras.h" |
Benjamin Kramer | 1a25d73 | 2009-08-23 11:37:21 +0000 | [diff] [blame] | 34 | #include "llvm/Support/raw_ostream.h" |
Bill Wendling | d2e493b | 2013-01-24 00:06:56 +0000 | [diff] [blame] | 35 | #include <algorithm> |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 36 | #include <cassert> |
| 37 | #include <cstdint> |
| 38 | #include <limits> |
| 39 | #include <map> |
| 40 | #include <string> |
| 41 | #include <tuple> |
| 42 | #include <utility> |
| 43 | |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 44 | using namespace llvm; |
| 45 | |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 46 | //===----------------------------------------------------------------------===// |
Bill Wendling | 7707c5a | 2013-01-29 00:48:16 +0000 | [diff] [blame] | 47 | // Attribute Construction Methods |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 48 | //===----------------------------------------------------------------------===// |
Chris Lattner | d0e1f10 | 2008-01-03 00:10:22 +0000 | [diff] [blame] | 49 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 50 | // allocsize has two integer arguments, but because they're both 32 bits, we can |
| 51 | // pack them into one 64-bit value, at the cost of making said value |
| 52 | // nonsensical. |
| 53 | // |
| 54 | // In order to do this, we need to reserve one value of the second (optional) |
| 55 | // allocsize argument to signify "not present." |
George Burgess IV | 381fc0e | 2016-08-25 01:05:08 +0000 | [diff] [blame] | 56 | static const unsigned AllocSizeNumElemsNotPresent = -1; |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 57 | |
| 58 | static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, |
| 59 | const Optional<unsigned> &NumElemsArg) { |
| 60 | assert((!NumElemsArg.hasValue() || |
| 61 | *NumElemsArg != AllocSizeNumElemsNotPresent) && |
| 62 | "Attempting to pack a reserved value"); |
| 63 | |
| 64 | return uint64_t(ElemSizeArg) << 32 | |
| 65 | NumElemsArg.getValueOr(AllocSizeNumElemsNotPresent); |
| 66 | } |
| 67 | |
| 68 | static std::pair<unsigned, Optional<unsigned>> |
| 69 | unpackAllocSizeArgs(uint64_t Num) { |
| 70 | unsigned NumElems = Num & std::numeric_limits<unsigned>::max(); |
| 71 | unsigned ElemSizeArg = Num >> 32; |
| 72 | |
| 73 | Optional<unsigned> NumElemsArg; |
| 74 | if (NumElems != AllocSizeNumElemsNotPresent) |
| 75 | NumElemsArg = NumElems; |
| 76 | return std::make_pair(ElemSizeArg, NumElemsArg); |
| 77 | } |
| 78 | |
Matt Arsenault | e1cef6e | 2014-09-03 23:24:31 +0000 | [diff] [blame] | 79 | Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, |
| 80 | uint64_t Val) { |
| 81 | LLVMContextImpl *pImpl = Context.pImpl; |
| 82 | FoldingSetNodeID ID; |
| 83 | ID.AddInteger(Kind); |
Matt Arsenault | fb4308e | 2014-09-03 23:38:05 +0000 | [diff] [blame] | 84 | if (Val) ID.AddInteger(Val); |
Matt Arsenault | e1cef6e | 2014-09-03 23:24:31 +0000 | [diff] [blame] | 85 | |
| 86 | void *InsertPoint; |
| 87 | AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
| 88 | |
| 89 | if (!PA) { |
| 90 | // If we didn't find any existing attributes of the same shape then create a |
| 91 | // new one and insert it. |
Matt Arsenault | fb4308e | 2014-09-03 23:38:05 +0000 | [diff] [blame] | 92 | if (!Val) |
| 93 | PA = new EnumAttributeImpl(Kind); |
| 94 | else |
| 95 | PA = new IntAttributeImpl(Kind, Val); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 96 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 97 | } |
| 98 | |
| 99 | // Return the Attribute that we found or created. |
| 100 | return Attribute(PA); |
| 101 | } |
| 102 | |
| 103 | Attribute Attribute::get(LLVMContext &Context, StringRef Kind, StringRef Val) { |
| 104 | LLVMContextImpl *pImpl = Context.pImpl; |
| 105 | FoldingSetNodeID ID; |
| 106 | ID.AddString(Kind); |
| 107 | if (!Val.empty()) ID.AddString(Val); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 108 | |
| 109 | void *InsertPoint; |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 110 | AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 111 | |
| 112 | if (!PA) { |
| 113 | // If we didn't find any existing attributes of the same shape then create a |
| 114 | // new one and insert it. |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 115 | PA = new StringAttributeImpl(Kind, Val); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 116 | pImpl->AttrsSet.InsertNode(PA, InsertPoint); |
| 117 | } |
| 118 | |
Bill Wendling | b9c5b1a | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 119 | // Return the Attribute that we found or created. |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 120 | return Attribute(PA); |
Bill Wendling | 73ea2de | 2012-10-08 21:47:17 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Bill Wendling | 4bbe9db | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 123 | Attribute Attribute::getWithAlignment(LLVMContext &Context, uint64_t Align) { |
Bill Wendling | 1c7cc8a | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 124 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 125 | assert(Align <= 0x40000000 && "Alignment too large."); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 126 | return get(Context, Alignment, Align); |
Bill Wendling | 4bbe9db | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | Attribute Attribute::getWithStackAlignment(LLVMContext &Context, |
| 130 | uint64_t Align) { |
Bill Wendling | 1c7cc8a | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 131 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 132 | assert(Align <= 0x100 && "Alignment too large."); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 133 | return get(Context, StackAlignment, Align); |
Bill Wendling | 4bbe9db | 2013-01-27 22:43:04 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 136 | Attribute Attribute::getWithDereferenceableBytes(LLVMContext &Context, |
| 137 | uint64_t Bytes) { |
| 138 | assert(Bytes && "Bytes must be non-zero."); |
| 139 | return get(Context, Dereferenceable, Bytes); |
| 140 | } |
| 141 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 142 | Attribute Attribute::getWithDereferenceableOrNullBytes(LLVMContext &Context, |
| 143 | uint64_t Bytes) { |
| 144 | assert(Bytes && "Bytes must be non-zero."); |
| 145 | return get(Context, DereferenceableOrNull, Bytes); |
| 146 | } |
| 147 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 148 | Attribute |
| 149 | Attribute::getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, |
| 150 | const Optional<unsigned> &NumElemsArg) { |
| 151 | assert(!(ElemSizeArg == 0 && NumElemsArg && *NumElemsArg == 0) && |
| 152 | "Invalid allocsize arguments -- given allocsize(0, 0)"); |
| 153 | return get(Context, AllocSize, packAllocSizeArgs(ElemSizeArg, NumElemsArg)); |
| 154 | } |
| 155 | |
Bill Wendling | 7707c5a | 2013-01-29 00:48:16 +0000 | [diff] [blame] | 156 | //===----------------------------------------------------------------------===// |
| 157 | // Attribute Accessor Methods |
| 158 | //===----------------------------------------------------------------------===// |
| 159 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 160 | bool Attribute::isEnumAttribute() const { |
| 161 | return pImpl && pImpl->isEnumAttribute(); |
| 162 | } |
| 163 | |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 164 | bool Attribute::isIntAttribute() const { |
| 165 | return pImpl && pImpl->isIntAttribute(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | bool Attribute::isStringAttribute() const { |
| 169 | return pImpl && pImpl->isStringAttribute(); |
| 170 | } |
| 171 | |
| 172 | Attribute::AttrKind Attribute::getKindAsEnum() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 173 | if (!pImpl) return None; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 174 | assert((isEnumAttribute() || isIntAttribute()) && |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 175 | "Invalid attribute type to get the kind as an enum!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame] | 176 | return pImpl->getKindAsEnum(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | uint64_t Attribute::getValueAsInt() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 180 | if (!pImpl) return 0; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 181 | assert(isIntAttribute() && |
| 182 | "Expected the attribute to be an integer attribute!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame] | 183 | return pImpl->getValueAsInt(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | StringRef Attribute::getKindAsString() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 187 | if (!pImpl) return StringRef(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 188 | assert(isStringAttribute() && |
| 189 | "Invalid attribute type to get the kind as a string!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame] | 190 | return pImpl->getKindAsString(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | StringRef Attribute::getValueAsString() const { |
Bill Wendling | 440e9d8 | 2013-07-25 00:34:29 +0000 | [diff] [blame] | 194 | if (!pImpl) return StringRef(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 195 | assert(isStringAttribute() && |
| 196 | "Invalid attribute type to get the value as a string!"); |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame] | 197 | return pImpl->getValueAsString(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Bill Wendling | ae89a0f | 2013-02-05 23:48:36 +0000 | [diff] [blame] | 200 | bool Attribute::hasAttribute(AttrKind Kind) const { |
| 201 | return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None); |
| 202 | } |
| 203 | |
| 204 | bool Attribute::hasAttribute(StringRef Kind) const { |
| 205 | if (!isStringAttribute()) return false; |
| 206 | return pImpl && pImpl->hasAttribute(Kind); |
Bill Wendling | 03eefb3 | 2013-01-29 20:45:34 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 209 | unsigned Attribute::getAlignment() const { |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 210 | assert(hasAttribute(Attribute::Alignment) && |
| 211 | "Trying to get alignment from non-alignment attribute!"); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 212 | return pImpl->getValueAsInt(); |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 215 | unsigned Attribute::getStackAlignment() const { |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 216 | assert(hasAttribute(Attribute::StackAlignment) && |
| 217 | "Trying to get alignment from non-alignment attribute!"); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 218 | return pImpl->getValueAsInt(); |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 221 | uint64_t Attribute::getDereferenceableBytes() const { |
| 222 | assert(hasAttribute(Attribute::Dereferenceable) && |
| 223 | "Trying to get dereferenceable bytes from " |
| 224 | "non-dereferenceable attribute!"); |
| 225 | return pImpl->getValueAsInt(); |
| 226 | } |
| 227 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 228 | uint64_t Attribute::getDereferenceableOrNullBytes() const { |
| 229 | assert(hasAttribute(Attribute::DereferenceableOrNull) && |
| 230 | "Trying to get dereferenceable bytes from " |
| 231 | "non-dereferenceable attribute!"); |
| 232 | return pImpl->getValueAsInt(); |
| 233 | } |
| 234 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 235 | std::pair<unsigned, Optional<unsigned>> Attribute::getAllocSizeArgs() const { |
| 236 | assert(hasAttribute(Attribute::AllocSize) && |
| 237 | "Trying to get allocsize args from non-allocsize attribute"); |
| 238 | return unpackAllocSizeArgs(pImpl->getValueAsInt()); |
| 239 | } |
| 240 | |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 241 | std::string Attribute::getAsString(bool InAttrGrp) const { |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 242 | if (!pImpl) return ""; |
| 243 | |
Kostya Serebryany | cf880b9 | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 244 | if (hasAttribute(Attribute::SanitizeAddress)) |
| 245 | return "sanitize_address"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 246 | if (hasAttribute(Attribute::AlwaysInline)) |
| 247 | return "alwaysinline"; |
Igor Laevsky | 39d662f | 2015-07-11 10:30:36 +0000 | [diff] [blame] | 248 | if (hasAttribute(Attribute::ArgMemOnly)) |
| 249 | return "argmemonly"; |
Michael Gottesman | 41748d7 | 2013-06-27 00:25:01 +0000 | [diff] [blame] | 250 | if (hasAttribute(Attribute::Builtin)) |
| 251 | return "builtin"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 252 | if (hasAttribute(Attribute::ByVal)) |
| 253 | return "byval"; |
Owen Anderson | 85fa7d5 | 2015-05-26 23:48:40 +0000 | [diff] [blame] | 254 | if (hasAttribute(Attribute::Convergent)) |
| 255 | return "convergent"; |
Manman Ren | 9bfd0d0 | 2016-04-01 21:41:15 +0000 | [diff] [blame] | 256 | if (hasAttribute(Attribute::SwiftError)) |
| 257 | return "swifterror"; |
Manman Ren | f46262e | 2016-03-29 17:37:21 +0000 | [diff] [blame] | 258 | if (hasAttribute(Attribute::SwiftSelf)) |
| 259 | return "swiftself"; |
Vaivaswatha Nagaraj | fb3f490 | 2015-12-16 16:16:19 +0000 | [diff] [blame] | 260 | if (hasAttribute(Attribute::InaccessibleMemOnly)) |
| 261 | return "inaccessiblememonly"; |
| 262 | if (hasAttribute(Attribute::InaccessibleMemOrArgMemOnly)) |
| 263 | return "inaccessiblemem_or_argmemonly"; |
Reid Kleckner | a534a38 | 2013-12-19 02:14:12 +0000 | [diff] [blame] | 264 | if (hasAttribute(Attribute::InAlloca)) |
| 265 | return "inalloca"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 266 | if (hasAttribute(Attribute::InlineHint)) |
| 267 | return "inlinehint"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 268 | if (hasAttribute(Attribute::InReg)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 269 | return "inreg"; |
Tom Roeder | 44cb65f | 2014-06-05 19:29:43 +0000 | [diff] [blame] | 270 | if (hasAttribute(Attribute::JumpTable)) |
| 271 | return "jumptable"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 272 | if (hasAttribute(Attribute::MinSize)) |
| 273 | return "minsize"; |
| 274 | if (hasAttribute(Attribute::Naked)) |
| 275 | return "naked"; |
| 276 | if (hasAttribute(Attribute::Nest)) |
| 277 | return "nest"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 278 | if (hasAttribute(Attribute::NoAlias)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 279 | return "noalias"; |
Bill Wendling | 09bd1f7 | 2013-02-22 00:12:35 +0000 | [diff] [blame] | 280 | if (hasAttribute(Attribute::NoBuiltin)) |
| 281 | return "nobuiltin"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 282 | if (hasAttribute(Attribute::NoCapture)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 283 | return "nocapture"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 284 | if (hasAttribute(Attribute::NoDuplicate)) |
| 285 | return "noduplicate"; |
| 286 | if (hasAttribute(Attribute::NoImplicitFloat)) |
| 287 | return "noimplicitfloat"; |
| 288 | if (hasAttribute(Attribute::NoInline)) |
| 289 | return "noinline"; |
| 290 | if (hasAttribute(Attribute::NonLazyBind)) |
| 291 | return "nonlazybind"; |
Nick Lewycky | d52b152 | 2014-05-20 01:23:40 +0000 | [diff] [blame] | 292 | if (hasAttribute(Attribute::NonNull)) |
| 293 | return "nonnull"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 294 | if (hasAttribute(Attribute::NoRedZone)) |
| 295 | return "noredzone"; |
| 296 | if (hasAttribute(Attribute::NoReturn)) |
| 297 | return "noreturn"; |
James Molloy | e6f87ca | 2015-11-06 10:32:53 +0000 | [diff] [blame] | 298 | if (hasAttribute(Attribute::NoRecurse)) |
| 299 | return "norecurse"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 300 | if (hasAttribute(Attribute::NoUnwind)) |
| 301 | return "nounwind"; |
Andrea Di Biagio | 377496b | 2013-08-23 11:53:55 +0000 | [diff] [blame] | 302 | if (hasAttribute(Attribute::OptimizeNone)) |
| 303 | return "optnone"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 304 | if (hasAttribute(Attribute::OptimizeForSize)) |
| 305 | return "optsize"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 306 | if (hasAttribute(Attribute::ReadNone)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 307 | return "readnone"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 308 | if (hasAttribute(Attribute::ReadOnly)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 309 | return "readonly"; |
Nicolai Haehnle | 84c9f99 | 2016-07-04 08:01:29 +0000 | [diff] [blame] | 310 | if (hasAttribute(Attribute::WriteOnly)) |
| 311 | return "writeonly"; |
Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 312 | if (hasAttribute(Attribute::Returned)) |
| 313 | return "returned"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 314 | if (hasAttribute(Attribute::ReturnsTwice)) |
| 315 | return "returns_twice"; |
| 316 | if (hasAttribute(Attribute::SExt)) |
| 317 | return "signext"; |
Matt Arsenault | b19b57e | 2017-04-28 20:25:27 +0000 | [diff] [blame] | 318 | if (hasAttribute(Attribute::Speculatable)) |
| 319 | return "speculatable"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 320 | if (hasAttribute(Attribute::StackProtect)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 321 | return "ssp"; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 322 | if (hasAttribute(Attribute::StackProtectReq)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 323 | return "sspreq"; |
Bill Wendling | d154e283 | 2013-01-23 06:41:41 +0000 | [diff] [blame] | 324 | if (hasAttribute(Attribute::StackProtectStrong)) |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 325 | return "sspstrong"; |
Peter Collingbourne | 82437bf | 2015-06-15 21:07:11 +0000 | [diff] [blame] | 326 | if (hasAttribute(Attribute::SafeStack)) |
| 327 | return "safestack"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 328 | if (hasAttribute(Attribute::StructRet)) |
| 329 | return "sret"; |
Kostya Serebryany | cf880b9 | 2013-02-26 06:58:09 +0000 | [diff] [blame] | 330 | if (hasAttribute(Attribute::SanitizeThread)) |
| 331 | return "sanitize_thread"; |
| 332 | if (hasAttribute(Attribute::SanitizeMemory)) |
| 333 | return "sanitize_memory"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 334 | if (hasAttribute(Attribute::UWTable)) |
| 335 | return "uwtable"; |
| 336 | if (hasAttribute(Attribute::ZExt)) |
| 337 | return "zeroext"; |
Diego Novillo | c639953 | 2013-05-24 12:26:52 +0000 | [diff] [blame] | 338 | if (hasAttribute(Attribute::Cold)) |
| 339 | return "cold"; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 340 | |
| 341 | // FIXME: These should be output like this: |
| 342 | // |
| 343 | // align=4 |
| 344 | // alignstack=8 |
| 345 | // |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 346 | if (hasAttribute(Attribute::Alignment)) { |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 347 | std::string Result; |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 348 | Result += "align"; |
| 349 | Result += (InAttrGrp) ? "=" : " "; |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 350 | Result += utostr(getValueAsInt()); |
| 351 | return Result; |
| 352 | } |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 353 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 354 | auto AttrWithBytesToString = [&](const char *Name) { |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 355 | std::string Result; |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 356 | Result += Name; |
Bill Wendling | 829b478 | 2013-02-11 08:43:33 +0000 | [diff] [blame] | 357 | if (InAttrGrp) { |
| 358 | Result += "="; |
| 359 | Result += utostr(getValueAsInt()); |
| 360 | } else { |
| 361 | Result += "("; |
| 362 | Result += utostr(getValueAsInt()); |
| 363 | Result += ")"; |
| 364 | } |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 365 | return Result; |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 366 | }; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 367 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 368 | if (hasAttribute(Attribute::StackAlignment)) |
| 369 | return AttrWithBytesToString("alignstack"); |
| 370 | |
| 371 | if (hasAttribute(Attribute::Dereferenceable)) |
| 372 | return AttrWithBytesToString("dereferenceable"); |
| 373 | |
| 374 | if (hasAttribute(Attribute::DereferenceableOrNull)) |
| 375 | return AttrWithBytesToString("dereferenceable_or_null"); |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 376 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 377 | if (hasAttribute(Attribute::AllocSize)) { |
| 378 | unsigned ElemSize; |
| 379 | Optional<unsigned> NumElems; |
| 380 | std::tie(ElemSize, NumElems) = getAllocSizeArgs(); |
| 381 | |
| 382 | std::string Result = "allocsize("; |
| 383 | Result += utostr(ElemSize); |
| 384 | if (NumElems.hasValue()) { |
| 385 | Result += ','; |
| 386 | Result += utostr(*NumElems); |
| 387 | } |
| 388 | Result += ')'; |
| 389 | return Result; |
| 390 | } |
| 391 | |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 392 | // Convert target-dependent attributes to strings of the form: |
| 393 | // |
| 394 | // "kind" |
| 395 | // "kind" = "value" |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 396 | // |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 397 | if (isStringAttribute()) { |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 398 | std::string Result; |
Yaron Keren | 075759a | 2015-03-30 15:42:36 +0000 | [diff] [blame] | 399 | Result += (Twine('"') + getKindAsString() + Twine('"')).str(); |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 400 | |
Honggyu Kim | 9eb6a10 | 2016-09-01 11:44:06 +0000 | [diff] [blame] | 401 | std::string AttrVal = pImpl->getValueAsString(); |
| 402 | if (AttrVal.empty()) return Result; |
Bill Wendling | 7a33f77 | 2013-02-01 22:32:30 +0000 | [diff] [blame] | 403 | |
Honggyu Kim | 9eb6a10 | 2016-09-01 11:44:06 +0000 | [diff] [blame] | 404 | // Since some attribute strings contain special characters that cannot be |
| 405 | // printable, those have to be escaped to make the attribute value printable |
| 406 | // as is. e.g. "\01__gnu_mcount_nc" |
| 407 | { |
| 408 | raw_string_ostream OS(Result); |
| 409 | OS << "=\""; |
| 410 | PrintEscapedString(AttrVal, OS); |
| 411 | OS << "\""; |
| 412 | } |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 413 | return Result; |
Bill Wendling | 9c2eba9 | 2013-01-31 20:59:05 +0000 | [diff] [blame] | 414 | } |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 415 | |
| 416 | llvm_unreachable("Unknown attribute"); |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 419 | bool Attribute::operator<(Attribute A) const { |
| 420 | if (!pImpl && !A.pImpl) return false; |
| 421 | if (!pImpl) return true; |
| 422 | if (!A.pImpl) return false; |
| 423 | return *pImpl < *A.pImpl; |
| 424 | } |
| 425 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 426 | //===----------------------------------------------------------------------===// |
| 427 | // AttributeImpl Definition |
| 428 | //===----------------------------------------------------------------------===// |
| 429 | |
Eric Christopher | 0eaa541 | 2014-07-02 22:05:40 +0000 | [diff] [blame] | 430 | // Pin the vtables to this file. |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 431 | AttributeImpl::~AttributeImpl() = default; |
| 432 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 433 | void EnumAttributeImpl::anchor() {} |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 434 | |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 435 | void IntAttributeImpl::anchor() {} |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 436 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 437 | void StringAttributeImpl::anchor() {} |
Alexey Samsonov | 49109a2 | 2013-11-18 09:31:53 +0000 | [diff] [blame] | 438 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 439 | bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const { |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 440 | if (isStringAttribute()) return false; |
| 441 | return getKindAsEnum() == A; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 444 | bool AttributeImpl::hasAttribute(StringRef Kind) const { |
| 445 | if (!isStringAttribute()) return false; |
| 446 | return getKindAsString() == Kind; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 449 | Attribute::AttrKind AttributeImpl::getKindAsEnum() const { |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 450 | assert(isEnumAttribute() || isIntAttribute()); |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 451 | return static_cast<const EnumAttributeImpl *>(this)->getEnumKind(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 454 | uint64_t AttributeImpl::getValueAsInt() const { |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 455 | assert(isIntAttribute()); |
| 456 | return static_cast<const IntAttributeImpl *>(this)->getValue(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 459 | StringRef AttributeImpl::getKindAsString() const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 460 | assert(isStringAttribute()); |
| 461 | return static_cast<const StringAttributeImpl *>(this)->getStringKind(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 464 | StringRef AttributeImpl::getValueAsString() const { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 465 | assert(isStringAttribute()); |
| 466 | return static_cast<const StringAttributeImpl *>(this)->getStringValue(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | bool AttributeImpl::operator<(const AttributeImpl &AI) const { |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 470 | // This sorts the attributes with Attribute::AttrKinds coming first (sorted |
| 471 | // relative to their enum value) and then strings. |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 472 | if (isEnumAttribute()) { |
| 473 | if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum(); |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 474 | if (AI.isIntAttribute()) return true; |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 475 | if (AI.isStringAttribute()) return true; |
| 476 | } |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 477 | |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 478 | if (isIntAttribute()) { |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 479 | if (AI.isEnumAttribute()) return false; |
Reid Kleckner | 7de6761 | 2016-04-04 23:06:05 +0000 | [diff] [blame] | 480 | if (AI.isIntAttribute()) { |
| 481 | if (getKindAsEnum() == AI.getKindAsEnum()) |
| 482 | return getValueAsInt() < AI.getValueAsInt(); |
| 483 | return getKindAsEnum() < AI.getKindAsEnum(); |
| 484 | } |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 485 | if (AI.isStringAttribute()) return true; |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 486 | } |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 487 | |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 488 | if (AI.isEnumAttribute()) return false; |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 489 | if (AI.isIntAttribute()) return false; |
Bill Wendling | 26b9575 | 2013-02-15 05:25:26 +0000 | [diff] [blame] | 490 | if (getKindAsString() == AI.getKindAsString()) |
| 491 | return getValueAsString() < AI.getValueAsString(); |
| 492 | return getKindAsString() < AI.getKindAsString(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 493 | } |
| 494 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 495 | //===----------------------------------------------------------------------===// |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 496 | // AttributeSet Definition |
| 497 | //===----------------------------------------------------------------------===// |
| 498 | |
| 499 | AttributeSet AttributeSet::get(LLVMContext &C, const AttrBuilder &B) { |
| 500 | return AttributeSet(AttributeSetNode::get(C, B)); |
| 501 | } |
| 502 | |
| 503 | AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<Attribute> Attrs) { |
| 504 | return AttributeSet(AttributeSetNode::get(C, Attrs)); |
| 505 | } |
| 506 | |
| 507 | unsigned AttributeSet::getNumAttributes() const { |
| 508 | return SetNode ? SetNode->getNumAttributes() : 0; |
| 509 | } |
| 510 | |
| 511 | bool AttributeSet::hasAttribute(Attribute::AttrKind Kind) const { |
| 512 | return SetNode ? SetNode->hasAttribute(Kind) : 0; |
| 513 | } |
| 514 | |
| 515 | bool AttributeSet::hasAttribute(StringRef Kind) const { |
| 516 | return SetNode ? SetNode->hasAttribute(Kind) : 0; |
| 517 | } |
| 518 | |
| 519 | Attribute AttributeSet::getAttribute(Attribute::AttrKind Kind) const { |
| 520 | return SetNode ? SetNode->getAttribute(Kind) : Attribute(); |
| 521 | } |
| 522 | |
| 523 | Attribute AttributeSet::getAttribute(StringRef Kind) const { |
| 524 | return SetNode ? SetNode->getAttribute(Kind) : Attribute(); |
| 525 | } |
| 526 | |
| 527 | unsigned AttributeSet::getAlignment() const { |
| 528 | return SetNode ? SetNode->getAlignment() : 0; |
| 529 | } |
| 530 | |
| 531 | unsigned AttributeSet::getStackAlignment() const { |
| 532 | return SetNode ? SetNode->getStackAlignment() : 0; |
| 533 | } |
| 534 | |
| 535 | uint64_t AttributeSet::getDereferenceableBytes() const { |
| 536 | return SetNode ? SetNode->getDereferenceableBytes() : 0; |
| 537 | } |
| 538 | |
| 539 | uint64_t AttributeSet::getDereferenceableOrNullBytes() const { |
| 540 | return SetNode ? SetNode->getDereferenceableOrNullBytes() : 0; |
| 541 | } |
| 542 | |
| 543 | std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const { |
Konstantin Zhuravlyov | 6df95b7 | 2017-04-12 23:57:37 +0000 | [diff] [blame] | 544 | return SetNode ? SetNode->getAllocSizeArgs() |
| 545 | : std::pair<unsigned, Optional<unsigned>>(0, 0); |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | std::string AttributeSet::getAsString(bool InAttrGrp) const { |
| 549 | return SetNode ? SetNode->getAsString(InAttrGrp) : ""; |
| 550 | } |
| 551 | |
| 552 | AttributeSet::iterator AttributeSet::begin() const { |
| 553 | return SetNode ? SetNode->begin() : nullptr; |
| 554 | } |
| 555 | |
| 556 | AttributeSet::iterator AttributeSet::end() const { |
| 557 | return SetNode ? SetNode->end() : nullptr; |
| 558 | } |
| 559 | |
| 560 | //===----------------------------------------------------------------------===// |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 561 | // AttributeSetNode Definition |
| 562 | //===----------------------------------------------------------------------===// |
| 563 | |
Reid Kleckner | 8ff7785 | 2017-04-10 23:46:08 +0000 | [diff] [blame] | 564 | AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs) |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 565 | : AvailableAttrs(0), NumAttrs(Attrs.size()) { |
Reid Kleckner | 8ff7785 | 2017-04-10 23:46:08 +0000 | [diff] [blame] | 566 | // There's memory after the node where we can store the entries in. |
| 567 | std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>()); |
| 568 | |
| 569 | for (Attribute I : *this) { |
| 570 | if (!I.isStringAttribute()) { |
| 571 | AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum(); |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 576 | AttributeSetNode *AttributeSetNode::get(LLVMContext &C, |
| 577 | ArrayRef<Attribute> Attrs) { |
| 578 | if (Attrs.empty()) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 579 | return nullptr; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 580 | |
| 581 | // Otherwise, build a key to look up the existing attributes. |
| 582 | LLVMContextImpl *pImpl = C.pImpl; |
| 583 | FoldingSetNodeID ID; |
| 584 | |
| 585 | SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end()); |
Reid Kleckner | 7de6761 | 2016-04-04 23:06:05 +0000 | [diff] [blame] | 586 | std::sort(SortedAttrs.begin(), SortedAttrs.end()); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 587 | |
George Burgess IV | 500d303 | 2015-12-16 05:21:02 +0000 | [diff] [blame] | 588 | for (Attribute Attr : SortedAttrs) |
| 589 | Attr.Profile(ID); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 590 | |
| 591 | void *InsertPoint; |
| 592 | AttributeSetNode *PA = |
| 593 | pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint); |
| 594 | |
| 595 | // If we didn't find any existing attributes of the same shape then create a |
| 596 | // new one and insert it. |
| 597 | if (!PA) { |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 598 | // Coallocate entries after the AttributeSetNode itself. |
James Y Knight | aa365b2 | 2015-08-05 22:57:34 +0000 | [diff] [blame] | 599 | void *Mem = ::operator new(totalSizeToAlloc<Attribute>(SortedAttrs.size())); |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 600 | PA = new (Mem) AttributeSetNode(SortedAttrs); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 601 | pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint); |
| 602 | } |
| 603 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 604 | // Return the AttributeSetNode that we found or created. |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 605 | return PA; |
| 606 | } |
| 607 | |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 608 | AttributeSetNode *AttributeSetNode::get(LLVMContext &C, const AttrBuilder &B) { |
| 609 | // Add target-independent attributes. |
| 610 | SmallVector<Attribute, 8> Attrs; |
| 611 | for (Attribute::AttrKind Kind = Attribute::None; |
| 612 | Kind != Attribute::EndAttrKinds; Kind = Attribute::AttrKind(Kind + 1)) { |
| 613 | if (!B.contains(Kind)) |
| 614 | continue; |
| 615 | |
| 616 | Attribute Attr; |
| 617 | switch (Kind) { |
| 618 | case Attribute::Alignment: |
| 619 | Attr = Attribute::getWithAlignment(C, B.getAlignment()); |
| 620 | break; |
| 621 | case Attribute::StackAlignment: |
| 622 | Attr = Attribute::getWithStackAlignment(C, B.getStackAlignment()); |
| 623 | break; |
| 624 | case Attribute::Dereferenceable: |
| 625 | Attr = Attribute::getWithDereferenceableBytes( |
| 626 | C, B.getDereferenceableBytes()); |
| 627 | break; |
| 628 | case Attribute::DereferenceableOrNull: |
| 629 | Attr = Attribute::getWithDereferenceableOrNullBytes( |
| 630 | C, B.getDereferenceableOrNullBytes()); |
| 631 | break; |
| 632 | case Attribute::AllocSize: { |
| 633 | auto A = B.getAllocSizeArgs(); |
| 634 | Attr = Attribute::getWithAllocSizeArgs(C, A.first, A.second); |
| 635 | break; |
| 636 | } |
| 637 | default: |
| 638 | Attr = Attribute::get(C, Kind); |
| 639 | } |
| 640 | Attrs.push_back(Attr); |
| 641 | } |
| 642 | |
| 643 | // Add target-dependent (string) attributes. |
| 644 | for (const auto &TDA : B.td_attrs()) |
| 645 | Attrs.emplace_back(Attribute::get(C, TDA.first, TDA.second)); |
| 646 | |
| 647 | return get(C, Attrs); |
| 648 | } |
| 649 | |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 650 | bool AttributeSetNode::hasAttribute(StringRef Kind) const { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 651 | for (Attribute I : *this) |
| 652 | if (I.hasAttribute(Kind)) |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 653 | return true; |
| 654 | return false; |
| 655 | } |
| 656 | |
| 657 | Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const { |
Matthias Braun | 31eeb76f | 2016-01-29 22:25:13 +0000 | [diff] [blame] | 658 | if (hasAttribute(Kind)) { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 659 | for (Attribute I : *this) |
| 660 | if (I.hasAttribute(Kind)) |
| 661 | return I; |
Matthias Braun | 31eeb76f | 2016-01-29 22:25:13 +0000 | [diff] [blame] | 662 | } |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 663 | return Attribute(); |
| 664 | } |
| 665 | |
| 666 | Attribute AttributeSetNode::getAttribute(StringRef Kind) const { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 667 | for (Attribute I : *this) |
| 668 | if (I.hasAttribute(Kind)) |
| 669 | return I; |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 670 | return Attribute(); |
| 671 | } |
| 672 | |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 673 | unsigned AttributeSetNode::getAlignment() const { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 674 | for (Attribute I : *this) |
| 675 | if (I.hasAttribute(Attribute::Alignment)) |
| 676 | return I.getAlignment(); |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | unsigned AttributeSetNode::getStackAlignment() const { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 681 | for (Attribute I : *this) |
| 682 | if (I.hasAttribute(Attribute::StackAlignment)) |
| 683 | return I.getStackAlignment(); |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 687 | uint64_t AttributeSetNode::getDereferenceableBytes() const { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 688 | for (Attribute I : *this) |
| 689 | if (I.hasAttribute(Attribute::Dereferenceable)) |
| 690 | return I.getDereferenceableBytes(); |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 691 | return 0; |
| 692 | } |
| 693 | |
Sanjoy Das | 06cf33f | 2015-05-06 17:41:54 +0000 | [diff] [blame] | 694 | uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 695 | for (Attribute I : *this) |
| 696 | if (I.hasAttribute(Attribute::DereferenceableOrNull)) |
| 697 | return I.getDereferenceableOrNullBytes(); |
Sanjoy Das | 06cf33f | 2015-05-06 17:41:54 +0000 | [diff] [blame] | 698 | return 0; |
| 699 | } |
| 700 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 701 | std::pair<unsigned, Optional<unsigned>> |
| 702 | AttributeSetNode::getAllocSizeArgs() const { |
Benjamin Kramer | af28e7d | 2016-06-26 14:10:56 +0000 | [diff] [blame] | 703 | for (Attribute I : *this) |
| 704 | if (I.hasAttribute(Attribute::AllocSize)) |
| 705 | return I.getAllocSizeArgs(); |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 706 | return std::make_pair(0, 0); |
| 707 | } |
| 708 | |
Rafael Espindola | cbf5a7a | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 709 | std::string AttributeSetNode::getAsString(bool InAttrGrp) const { |
Benjamin Kramer | 0baf8f4 | 2013-04-19 11:43:21 +0000 | [diff] [blame] | 710 | std::string Str; |
Benjamin Kramer | 741146b | 2013-07-11 12:13:16 +0000 | [diff] [blame] | 711 | for (iterator I = begin(), E = end(); I != E; ++I) { |
| 712 | if (I != begin()) |
Rafael Espindola | cbf5a7a | 2013-05-01 13:07:03 +0000 | [diff] [blame] | 713 | Str += ' '; |
| 714 | Str += I->getAsString(InAttrGrp); |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 715 | } |
| 716 | return Str; |
| 717 | } |
| 718 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 719 | //===----------------------------------------------------------------------===// |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 720 | // AttributeListImpl Definition |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 721 | //===----------------------------------------------------------------------===// |
| 722 | |
Reid Kleckner | a82be60 | 2017-04-11 00:16:00 +0000 | [diff] [blame] | 723 | AttributeListImpl::AttributeListImpl( |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 724 | LLVMContext &C, ArrayRef<std::pair<unsigned, AttributeSet>> Slots) |
Reid Kleckner | a82be60 | 2017-04-11 00:16:00 +0000 | [diff] [blame] | 725 | : Context(C), NumSlots(Slots.size()), AvailableFunctionAttrs(0) { |
| 726 | #ifndef NDEBUG |
Reid Kleckner | ec0fc03 | 2017-04-12 22:22:01 +0000 | [diff] [blame] | 727 | assert(!Slots.empty() && "pointless AttributeListImpl"); |
Reid Kleckner | a82be60 | 2017-04-11 00:16:00 +0000 | [diff] [blame] | 728 | if (Slots.size() >= 2) { |
| 729 | auto &PrevPair = Slots.front(); |
| 730 | for (auto &CurPair : Slots.drop_front()) { |
| 731 | assert(PrevPair.first <= CurPair.first && "Attribute set not ordered!"); |
| 732 | } |
| 733 | } |
| 734 | #endif |
| 735 | |
| 736 | // There's memory after the node where we can store the entries in. |
| 737 | std::copy(Slots.begin(), Slots.end(), getTrailingObjects<IndexAttrPair>()); |
| 738 | |
| 739 | // Initialize AvailableFunctionAttrs summary bitset. |
Reid Kleckner | ec0fc03 | 2017-04-12 22:22:01 +0000 | [diff] [blame] | 740 | static_assert(Attribute::EndAttrKinds <= |
| 741 | sizeof(AvailableFunctionAttrs) * CHAR_BIT, |
| 742 | "Too many attributes"); |
| 743 | static_assert(AttributeList::FunctionIndex == ~0u, |
| 744 | "FunctionIndex should be biggest possible index"); |
| 745 | const auto &Last = Slots.back(); |
| 746 | if (Last.first == AttributeList::FunctionIndex) { |
| 747 | AttributeSet Node = Last.second; |
| 748 | for (Attribute I : Node) { |
| 749 | if (!I.isStringAttribute()) |
| 750 | AvailableFunctionAttrs |= ((uint64_t)1) << I.getKindAsEnum(); |
Reid Kleckner | a82be60 | 2017-04-11 00:16:00 +0000 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | void AttributeListImpl::Profile(FoldingSetNodeID &ID) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 756 | Profile(ID, makeArrayRef(getSlotPair(0), getNumSlots())); |
Reid Kleckner | a82be60 | 2017-04-11 00:16:00 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | void AttributeListImpl::Profile( |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 760 | FoldingSetNodeID &ID, ArrayRef<std::pair<unsigned, AttributeSet>> Nodes) { |
Reid Kleckner | a82be60 | 2017-04-11 00:16:00 +0000 | [diff] [blame] | 761 | for (const auto &Node : Nodes) { |
| 762 | ID.AddInteger(Node.first); |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 763 | ID.AddPointer(Node.second.SetNode); |
Reid Kleckner | a82be60 | 2017-04-11 00:16:00 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 767 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 768 | LLVM_DUMP_METHOD void AttributeListImpl::dump() const { |
| 769 | AttributeList(const_cast<AttributeListImpl *>(this)).dump(); |
Peter Collingbourne | abca2ec | 2013-08-02 22:34:30 +0000 | [diff] [blame] | 770 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 771 | #endif |
Peter Collingbourne | abca2ec | 2013-08-02 22:34:30 +0000 | [diff] [blame] | 772 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 773 | //===----------------------------------------------------------------------===// |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 774 | // AttributeList Construction and Mutation Methods |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 775 | //===----------------------------------------------------------------------===// |
| 776 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 777 | AttributeList AttributeList::getImpl( |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 778 | LLVMContext &C, ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) { |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 779 | assert(!Attrs.empty() && "creating pointless AttributeList"); |
| 780 | #ifndef NDEBUG |
| 781 | unsigned LastIndex = 0; |
| 782 | bool IsFirst = true; |
Reid Kleckner | 7f72033 | 2017-04-13 00:58:09 +0000 | [diff] [blame] | 783 | for (auto &&AttrPair : Attrs) { |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 784 | assert((IsFirst || LastIndex < AttrPair.first) && |
| 785 | "unsorted or duplicate AttributeList indices"); |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 786 | assert(AttrPair.second.hasAttributes() && "pointless AttributeList slot"); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 787 | LastIndex = AttrPair.first; |
| 788 | IsFirst = false; |
| 789 | } |
| 790 | #endif |
| 791 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 792 | LLVMContextImpl *pImpl = C.pImpl; |
| 793 | FoldingSetNodeID ID; |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 794 | AttributeListImpl::Profile(ID, Attrs); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 795 | |
| 796 | void *InsertPoint; |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 797 | AttributeListImpl *PA = |
| 798 | pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 799 | |
| 800 | // If we didn't find any existing attributes of the same shape then |
| 801 | // create a new one and insert it. |
| 802 | if (!PA) { |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 803 | // Coallocate entries after the AttributeListImpl itself. |
James Y Knight | aa365b2 | 2015-08-05 22:57:34 +0000 | [diff] [blame] | 804 | void *Mem = ::operator new( |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 805 | AttributeListImpl::totalSizeToAlloc<IndexAttrPair>(Attrs.size())); |
| 806 | PA = new (Mem) AttributeListImpl(C, Attrs); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 807 | pImpl->AttrsLists.InsertNode(PA, InsertPoint); |
| 808 | } |
| 809 | |
| 810 | // Return the AttributesList that we found or created. |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 811 | return AttributeList(PA); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 814 | AttributeList |
| 815 | AttributeList::get(LLVMContext &C, |
| 816 | ArrayRef<std::pair<unsigned, Attribute>> Attrs) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 817 | // If there are no attributes then return a null AttributesList pointer. |
| 818 | if (Attrs.empty()) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 819 | return AttributeList(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 820 | |
Craig Topper | e30b8ca | 2016-01-03 19:43:40 +0000 | [diff] [blame] | 821 | assert(std::is_sorted(Attrs.begin(), Attrs.end(), |
| 822 | [](const std::pair<unsigned, Attribute> &LHS, |
| 823 | const std::pair<unsigned, Attribute> &RHS) { |
| 824 | return LHS.first < RHS.first; |
| 825 | }) && "Misordered Attributes list!"); |
David Majnemer | 0a16c22 | 2016-08-11 21:15:00 +0000 | [diff] [blame] | 826 | assert(none_of(Attrs, |
| 827 | [](const std::pair<unsigned, Attribute> &Pair) { |
| 828 | return Pair.second.hasAttribute(Attribute::None); |
| 829 | }) && |
| 830 | "Pointless attribute!"); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 831 | |
| 832 | // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes |
| 833 | // list. |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 834 | SmallVector<std::pair<unsigned, AttributeSet>, 8> AttrPairVec; |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 835 | for (ArrayRef<std::pair<unsigned, Attribute>>::iterator I = Attrs.begin(), |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 836 | E = Attrs.end(); I != E; ) { |
| 837 | unsigned Index = I->first; |
| 838 | SmallVector<Attribute, 4> AttrVec; |
NAKAMURA Takumi | f05d2f2 | 2013-01-29 15:18:16 +0000 | [diff] [blame] | 839 | while (I != E && I->first == Index) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 840 | AttrVec.push_back(I->second); |
| 841 | ++I; |
| 842 | } |
| 843 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 844 | AttrPairVec.emplace_back(Index, AttributeSet::get(C, AttrVec)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | return getImpl(C, AttrPairVec); |
| 848 | } |
| 849 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 850 | AttributeList |
| 851 | AttributeList::get(LLVMContext &C, |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 852 | ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 853 | // If there are no attributes then return a null AttributesList pointer. |
| 854 | if (Attrs.empty()) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 855 | return AttributeList(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 856 | |
| 857 | return getImpl(C, Attrs); |
| 858 | } |
| 859 | |
Reid Kleckner | 7f72033 | 2017-04-13 00:58:09 +0000 | [diff] [blame] | 860 | AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs, |
| 861 | AttributeSet RetAttrs, |
| 862 | ArrayRef<AttributeSet> ArgAttrs) { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 863 | SmallVector<std::pair<unsigned, AttributeSet>, 8> AttrPairs; |
Reid Kleckner | 7f72033 | 2017-04-13 00:58:09 +0000 | [diff] [blame] | 864 | if (RetAttrs.hasAttributes()) |
| 865 | AttrPairs.emplace_back(ReturnIndex, RetAttrs); |
| 866 | size_t Index = 1; |
| 867 | for (AttributeSet AS : ArgAttrs) { |
| 868 | if (AS.hasAttributes()) |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 869 | AttrPairs.emplace_back(Index, AS); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 870 | ++Index; |
| 871 | } |
Reid Kleckner | 7f72033 | 2017-04-13 00:58:09 +0000 | [diff] [blame] | 872 | if (FnAttrs.hasAttributes()) |
| 873 | AttrPairs.emplace_back(FunctionIndex, FnAttrs); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 874 | if (AttrPairs.empty()) |
| 875 | return AttributeList(); |
| 876 | return getImpl(C, AttrPairs); |
| 877 | } |
| 878 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 879 | AttributeList AttributeList::get(LLVMContext &C, unsigned Index, |
| 880 | const AttrBuilder &B) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 881 | if (!B.hasAttributes()) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 882 | return AttributeList(); |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 883 | AttributeSet AS = AttributeSet::get(C, B); |
| 884 | std::pair<unsigned, AttributeSet> Arr[1] = {{Index, AS}}; |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 885 | return getImpl(C, Arr); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 888 | AttributeList AttributeList::get(LLVMContext &C, unsigned Index, |
| 889 | ArrayRef<Attribute::AttrKind> Kinds) { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 890 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
Amaury Sechet | 392638d | 2016-06-14 20:27:35 +0000 | [diff] [blame] | 891 | for (Attribute::AttrKind K : Kinds) |
David Majnemer | 0a16c22 | 2016-08-11 21:15:00 +0000 | [diff] [blame] | 892 | Attrs.emplace_back(Index, Attribute::get(C, K)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 893 | return get(C, Attrs); |
| 894 | } |
| 895 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 896 | AttributeList AttributeList::get(LLVMContext &C, unsigned Index, |
| 897 | ArrayRef<StringRef> Kinds) { |
Amaury Sechet | 6100adf | 2016-06-15 17:50:39 +0000 | [diff] [blame] | 898 | SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; |
| 899 | for (StringRef K : Kinds) |
David Majnemer | 0a16c22 | 2016-08-11 21:15:00 +0000 | [diff] [blame] | 900 | Attrs.emplace_back(Index, Attribute::get(C, K)); |
Amaury Sechet | 6100adf | 2016-06-15 17:50:39 +0000 | [diff] [blame] | 901 | return get(C, Attrs); |
| 902 | } |
| 903 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 904 | AttributeList AttributeList::get(LLVMContext &C, |
| 905 | ArrayRef<AttributeList> Attrs) { |
| 906 | if (Attrs.empty()) |
| 907 | return AttributeList(); |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 908 | if (Attrs.size() == 1) return Attrs[0]; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 909 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 910 | SmallVector<std::pair<unsigned, AttributeSet>, 8> AttrNodeVec; |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 911 | AttributeListImpl *A0 = Attrs[0].pImpl; |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 912 | if (A0) |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 913 | AttrNodeVec.append(A0->getSlotPair(0), A0->getSlotPair(A0->getNumSlots())); |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 914 | // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec |
| 915 | // ordered by index. Because we know that each list in Attrs is ordered by |
| 916 | // index we only need to merge each successive list in rather than doing a |
| 917 | // full sort. |
| 918 | for (unsigned I = 1, E = Attrs.size(); I != E; ++I) { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 919 | AttributeListImpl *ALI = Attrs[I].pImpl; |
| 920 | if (!ALI) continue; |
| 921 | SmallVector<std::pair<unsigned, AttributeSet>, 8>::iterator |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 922 | ANVI = AttrNodeVec.begin(), ANVE; |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 923 | for (const IndexAttrPair *AI = ALI->getSlotPair(0), |
| 924 | *AE = ALI->getSlotPair(ALI->getNumSlots()); |
Peter Collingbourne | bd6c745 | 2013-08-02 22:29:40 +0000 | [diff] [blame] | 925 | AI != AE; ++AI) { |
| 926 | ANVE = AttrNodeVec.end(); |
| 927 | while (ANVI != ANVE && ANVI->first <= AI->first) |
| 928 | ++ANVI; |
| 929 | ANVI = AttrNodeVec.insert(ANVI, *AI) + 1; |
| 930 | } |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | return getImpl(C, AttrNodeVec); |
| 934 | } |
| 935 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 936 | AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, |
| 937 | Attribute::AttrKind Kind) const { |
Amaury Sechet | 392638d | 2016-06-14 20:27:35 +0000 | [diff] [blame] | 938 | if (hasAttribute(Index, Kind)) return *this; |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 939 | AttrBuilder B; |
| 940 | B.addAttribute(Kind); |
| 941 | return addAttributes(C, Index, B); |
Reed Kotler | 795c7b4 | 2013-03-13 20:20:08 +0000 | [diff] [blame] | 942 | } |
| 943 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 944 | AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, |
| 945 | StringRef Kind, |
| 946 | StringRef Value) const { |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 947 | AttrBuilder B; |
Bill Wendling | 3b2f610 | 2013-07-25 18:34:24 +0000 | [diff] [blame] | 948 | B.addAttribute(Kind, Value); |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 949 | return addAttributes(C, Index, B); |
Bill Wendling | 3b2f610 | 2013-07-25 18:34:24 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 952 | AttributeList AttributeList::addAttribute(LLVMContext &C, |
| 953 | ArrayRef<unsigned> Indices, |
| 954 | Attribute A) const { |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 955 | assert(std::is_sorted(Indices.begin(), Indices.end())); |
Reid Kleckner | 324c99d | 2017-04-10 20:18:10 +0000 | [diff] [blame] | 956 | |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 957 | unsigned I = 0, E = pImpl ? pImpl->getNumSlots() : 0; |
| 958 | SmallVector<IndexAttrPair, 4> AttrVec; |
| 959 | for (unsigned Index : Indices) { |
| 960 | // Add all attribute slots before the current index. |
| 961 | for (; I < E && getSlotIndex(I) < Index; ++I) |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 962 | AttrVec.emplace_back(getSlotIndex(I), pImpl->getSlotAttributes(I)); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 963 | |
| 964 | // Add the attribute at this index. If we already have attributes at this |
| 965 | // index, merge them into a new set. |
| 966 | AttrBuilder B; |
| 967 | if (I < E && getSlotIndex(I) == Index) { |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 968 | B.merge(AttrBuilder(pImpl->getSlotAttributes(I))); |
Akira Hatanaka | 237916b | 2015-12-02 06:58:49 +0000 | [diff] [blame] | 969 | ++I; |
Akira Hatanaka | 237916b | 2015-12-02 06:58:49 +0000 | [diff] [blame] | 970 | } |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 971 | B.addAttribute(A); |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 972 | AttrVec.emplace_back(Index, AttributeSet::get(C, B)); |
Akira Hatanaka | 237916b | 2015-12-02 06:58:49 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 975 | // Add remaining attributes. |
| 976 | for (; I < E; ++I) |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 977 | AttrVec.emplace_back(getSlotIndex(I), pImpl->getSlotAttributes(I)); |
Akira Hatanaka | 237916b | 2015-12-02 06:58:49 +0000 | [diff] [blame] | 978 | |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 979 | return get(C, AttrVec); |
Akira Hatanaka | 237916b | 2015-12-02 06:58:49 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 982 | AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index, |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 983 | const AttrBuilder &B) const { |
| 984 | if (!B.hasAttributes()) |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 985 | return *this; |
| 986 | |
Reid Kleckner | fe64c01 | 2017-04-18 22:10:18 +0000 | [diff] [blame] | 987 | if (!pImpl) |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 988 | return AttributeList::get(C, {{Index, AttributeSet::get(C, B)}}); |
Reid Kleckner | fe64c01 | 2017-04-18 22:10:18 +0000 | [diff] [blame] | 989 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 990 | #ifndef NDEBUG |
| 991 | // FIXME it is not obvious how this should work for alignment. For now, say |
| 992 | // we can't change a known alignment. |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 993 | unsigned OldAlign = getParamAlignment(Index); |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 994 | unsigned NewAlign = B.getAlignment(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 995 | assert((!OldAlign || !NewAlign || OldAlign == NewAlign) && |
| 996 | "Attempt to change alignment!"); |
| 997 | #endif |
| 998 | |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 999 | SmallVector<IndexAttrPair, 4> AttrVec; |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1000 | uint64_t NumAttrs = pImpl->getNumSlots(); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1001 | unsigned I; |
| 1002 | |
| 1003 | // Add all the attribute slots before the one we need to merge. |
| 1004 | for (I = 0; I < NumAttrs; ++I) { |
| 1005 | if (getSlotIndex(I) >= Index) |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1006 | break; |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1007 | AttrVec.emplace_back(getSlotIndex(I), pImpl->getSlotAttributes(I)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 1010 | AttrBuilder NewAttrs; |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1011 | if (I < NumAttrs && getSlotIndex(I) == Index) { |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 1012 | // We need to merge the attribute sets. |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1013 | NewAttrs.merge(pImpl->getSlotAttributes(I)); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1014 | ++I; |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1015 | } |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 1016 | NewAttrs.merge(B); |
| 1017 | |
| 1018 | // Add the new or merged attribute set at this index. |
| 1019 | AttrVec.emplace_back(Index, AttributeSet::get(C, NewAttrs)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1020 | |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1021 | // Add the remaining entries. |
| 1022 | for (; I < NumAttrs; ++I) |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1023 | AttrVec.emplace_back(getSlotIndex(I), pImpl->getSlotAttributes(I)); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1024 | |
Reid Kleckner | 6190625 | 2017-04-19 01:51:13 +0000 | [diff] [blame] | 1025 | return get(C, AttrVec); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1028 | AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index, |
| 1029 | Attribute::AttrKind Kind) const { |
Amaury Sechet | 392638d | 2016-06-14 20:27:35 +0000 | [diff] [blame] | 1030 | if (!hasAttribute(Index, Kind)) return *this; |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 1031 | AttrBuilder B; |
| 1032 | B.addAttribute(Kind); |
| 1033 | return removeAttributes(C, Index, B); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1036 | AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index, |
| 1037 | StringRef Kind) const { |
Amaury Sechet | 6100adf | 2016-06-15 17:50:39 +0000 | [diff] [blame] | 1038 | if (!hasAttribute(Index, Kind)) return *this; |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 1039 | AttrBuilder B; |
| 1040 | B.addAttribute(Kind); |
| 1041 | return removeAttributes(C, Index, B); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1044 | AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned Index, |
| 1045 | const AttrBuilder &Attrs) const { |
| 1046 | if (!pImpl) |
| 1047 | return AttributeList(); |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1048 | |
| 1049 | // FIXME it is not obvious how this should work for alignment. |
| 1050 | // For now, say we can't pass in alignment, which no current use does. |
| 1051 | assert(!Attrs.hasAlignmentAttr() && "Attempt to change alignment!"); |
| 1052 | |
| 1053 | // Add the attribute slots before the one we're trying to add. |
Reid Kleckner | 62731e1 | 2017-04-20 18:08:36 +0000 | [diff] [blame] | 1054 | SmallVector<IndexAttrPair, 4> AttrSets; |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1055 | uint64_t NumAttrs = pImpl->getNumSlots(); |
Reid Kleckner | 62731e1 | 2017-04-20 18:08:36 +0000 | [diff] [blame] | 1056 | AttrBuilder B; |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1057 | uint64_t LastIndex = 0; |
| 1058 | for (unsigned I = 0, E = NumAttrs; I != E; ++I) { |
| 1059 | if (getSlotIndex(I) >= Index) { |
Reid Kleckner | 62731e1 | 2017-04-20 18:08:36 +0000 | [diff] [blame] | 1060 | if (getSlotIndex(I) == Index) |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1061 | B = AttrBuilder(getSlotAttributes(LastIndex++)); |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1062 | break; |
| 1063 | } |
| 1064 | LastIndex = I + 1; |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1065 | AttrSets.push_back({getSlotIndex(I), getSlotAttributes(I)}); |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Reid Kleckner | 62731e1 | 2017-04-20 18:08:36 +0000 | [diff] [blame] | 1068 | // Remove the attributes from the existing set and add them. |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1069 | B.remove(Attrs); |
Reid Kleckner | 62731e1 | 2017-04-20 18:08:36 +0000 | [diff] [blame] | 1070 | if (B.hasAttributes()) |
| 1071 | AttrSets.push_back({Index, AttributeSet::get(C, B)}); |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1072 | |
| 1073 | // Add the remaining attribute slots. |
| 1074 | for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I) |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1075 | AttrSets.push_back({getSlotIndex(I), getSlotAttributes(I)}); |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1076 | |
Reid Kleckner | 62731e1 | 2017-04-20 18:08:36 +0000 | [diff] [blame] | 1077 | return get(C, AttrSets); |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1080 | AttributeList AttributeList::removeAttributes(LLVMContext &C, |
| 1081 | unsigned WithoutIndex) const { |
| 1082 | if (!pImpl) |
| 1083 | return AttributeList(); |
| 1084 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1085 | SmallVector<std::pair<unsigned, AttributeSet>, 4> AttrSet; |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1086 | for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) { |
| 1087 | unsigned Index = getSlotIndex(I); |
| 1088 | if (Index != WithoutIndex) |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1089 | AttrSet.push_back({Index, pImpl->getSlotAttributes(I)}); |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1090 | } |
| 1091 | return get(C, AttrSet); |
| 1092 | } |
| 1093 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1094 | AttributeList AttributeList::addDereferenceableAttr(LLVMContext &C, |
| 1095 | unsigned Index, |
| 1096 | uint64_t Bytes) const { |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 1097 | AttrBuilder B; |
Ramkumar Ramachandra | 8fcb498 | 2015-02-14 19:37:54 +0000 | [diff] [blame] | 1098 | B.addDereferenceableAttr(Bytes); |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 1099 | return addAttributes(C, Index, B); |
Ramkumar Ramachandra | 8fcb498 | 2015-02-14 19:37:54 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1102 | AttributeList |
| 1103 | AttributeList::addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, |
| 1104 | uint64_t Bytes) const { |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 1105 | AttrBuilder B; |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1106 | B.addDereferenceableOrNullAttr(Bytes); |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 1107 | return addAttributes(C, Index, B); |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1110 | AttributeList |
| 1111 | AttributeList::addAllocSizeAttr(LLVMContext &C, unsigned Index, |
| 1112 | unsigned ElemSizeArg, |
| 1113 | const Optional<unsigned> &NumElemsArg) { |
Eugene Zelenko | deaf695 | 2017-02-17 00:00:09 +0000 | [diff] [blame] | 1114 | AttrBuilder B; |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1115 | B.addAllocSizeAttr(ElemSizeArg, NumElemsArg); |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 1116 | return addAttributes(C, Index, B); |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1119 | //===----------------------------------------------------------------------===// |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1120 | // AttributeList Accessor Methods |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1121 | //===----------------------------------------------------------------------===// |
| 1122 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1123 | LLVMContext &AttributeList::getContext() const { return pImpl->getContext(); } |
| 1124 | |
Reid Kleckner | f021fab | 2017-04-13 23:12:13 +0000 | [diff] [blame] | 1125 | AttributeSet AttributeList::getParamAttributes(unsigned ArgNo) const { |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 1126 | return getAttributes(ArgNo + FirstArgIndex); |
Bill Wendling | 5d020a3 | 2013-02-10 05:00:40 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1129 | AttributeSet AttributeList::getRetAttributes() const { |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1130 | return getAttributes(ReturnIndex); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1133 | AttributeSet AttributeList::getFnAttributes() const { |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1134 | return getAttributes(FunctionIndex); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1137 | bool AttributeList::hasAttribute(unsigned Index, |
| 1138 | Attribute::AttrKind Kind) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1139 | return getAttributes(Index).hasAttribute(Kind); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1142 | bool AttributeList::hasAttribute(unsigned Index, StringRef Kind) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1143 | return getAttributes(Index).hasAttribute(Kind); |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1146 | bool AttributeList::hasAttributes(unsigned Index) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1147 | return getAttributes(Index).hasAttributes(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1150 | bool AttributeList::hasFnAttribute(Attribute::AttrKind Kind) const { |
Matthias Braun | 3328281 | 2016-01-29 22:25:19 +0000 | [diff] [blame] | 1151 | return pImpl && pImpl->hasFnAttribute(Kind); |
| 1152 | } |
| 1153 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1154 | bool AttributeList::hasFnAttribute(StringRef Kind) const { |
| 1155 | return hasAttribute(AttributeList::FunctionIndex, Kind); |
Amaury Sechet | 5f04d81 | 2016-09-09 04:50:38 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Reid Kleckner | f021fab | 2017-04-13 23:12:13 +0000 | [diff] [blame] | 1158 | bool AttributeList::hasParamAttribute(unsigned ArgNo, |
| 1159 | Attribute::AttrKind Kind) const { |
| 1160 | return hasAttribute(ArgNo + 1, Kind); |
| 1161 | } |
| 1162 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1163 | bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr, |
| 1164 | unsigned *Index) const { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 1165 | if (!pImpl) return false; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1166 | |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1167 | for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1168 | for (AttributeListImpl::iterator II = pImpl->begin(I), IE = pImpl->end(I); |
| 1169 | II != IE; ++II) |
Hal Finkel | e87ad54 | 2016-07-10 23:01:32 +0000 | [diff] [blame] | 1170 | if (II->hasAttribute(Attr)) { |
| 1171 | if (Index) *Index = pImpl->getSlotIndex(I); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1172 | return true; |
Hal Finkel | e87ad54 | 2016-07-10 23:01:32 +0000 | [diff] [blame] | 1173 | } |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1174 | |
| 1175 | return false; |
| 1176 | } |
| 1177 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1178 | Attribute AttributeList::getAttribute(unsigned Index, |
| 1179 | Attribute::AttrKind Kind) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1180 | return getAttributes(Index).getAttribute(Kind); |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1183 | Attribute AttributeList::getAttribute(unsigned Index, StringRef Kind) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1184 | return getAttributes(Index).getAttribute(Kind); |
Bill Wendling | bce7b97 | 2013-02-13 08:42:21 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Reid Kleckner | 859f8b5 | 2017-04-28 20:34:27 +0000 | [diff] [blame] | 1187 | unsigned AttributeList::getRetAlignment() const { |
| 1188 | return getAttributes(ReturnIndex).getAlignment(); |
| 1189 | } |
| 1190 | |
| 1191 | unsigned AttributeList::getParamAlignment(unsigned ArgNo) const { |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 1192 | return getAttributes(ArgNo + FirstArgIndex).getAlignment(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1195 | unsigned AttributeList::getStackAlignment(unsigned Index) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1196 | return getAttributes(Index).getStackAlignment(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1199 | uint64_t AttributeList::getDereferenceableBytes(unsigned Index) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1200 | return getAttributes(Index).getDereferenceableBytes(); |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1203 | uint64_t AttributeList::getDereferenceableOrNullBytes(unsigned Index) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1204 | return getAttributes(Index).getDereferenceableOrNullBytes(); |
Sanjoy Das | 06cf33f | 2015-05-06 17:41:54 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1207 | std::pair<unsigned, Optional<unsigned>> |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1208 | AttributeList::getAllocSizeArgs(unsigned Index) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1209 | return getAttributes(Index).getAllocSizeArgs(); |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1212 | std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const { |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1213 | return getAttributes(Index).getAsString(InAttrGrp); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1216 | AttributeSet AttributeList::getAttributes(unsigned Index) const { |
| 1217 | if (!pImpl) return AttributeSet(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1218 | |
Bill Wendling | f2955aa | 2013-01-29 03:20:31 +0000 | [diff] [blame] | 1219 | // Loop through to find the attribute node we want. |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1220 | for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1221 | if (pImpl->getSlotIndex(I) == Index) |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1222 | return pImpl->getSlotAttributes(I); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1223 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1224 | return AttributeSet(); |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1227 | AttributeList::iterator AttributeList::begin(unsigned Slot) const { |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1228 | if (!pImpl) |
| 1229 | return ArrayRef<Attribute>().begin(); |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1230 | return pImpl->begin(Slot); |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1233 | AttributeList::iterator AttributeList::end(unsigned Slot) const { |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1234 | if (!pImpl) |
| 1235 | return ArrayRef<Attribute>().end(); |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1236 | return pImpl->end(Slot); |
Bill Wendling | a917486 | 2013-01-31 23:53:05 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1239 | //===----------------------------------------------------------------------===// |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1240 | // AttributeList Introspection Methods |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1241 | //===----------------------------------------------------------------------===// |
| 1242 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1243 | unsigned AttributeList::getNumSlots() const { |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1244 | return pImpl ? pImpl->getNumSlots() : 0; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1247 | unsigned AttributeList::getSlotIndex(unsigned Slot) const { |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1248 | assert(pImpl && Slot < pImpl->getNumSlots() && |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1249 | "Slot # out of range!"); |
| 1250 | return pImpl->getSlotIndex(Slot); |
| 1251 | } |
| 1252 | |
Reid Kleckner | 63b26f0 | 2017-04-24 22:25:02 +0000 | [diff] [blame] | 1253 | AttributeSet AttributeList::getSlotAttributes(unsigned Slot) const { |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1254 | assert(pImpl && Slot < pImpl->getNumSlots() && |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1255 | "Slot # out of range!"); |
| 1256 | return pImpl->getSlotAttributes(Slot); |
| 1257 | } |
| 1258 | |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 1259 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1260 | LLVM_DUMP_METHOD void AttributeList::dump() const { |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1261 | dbgs() << "PAL[\n"; |
| 1262 | |
| 1263 | for (unsigned i = 0, e = getNumSlots(); i < e; ++i) { |
| 1264 | uint64_t Index = getSlotIndex(i); |
| 1265 | dbgs() << " { "; |
| 1266 | if (Index == ~0U) |
| 1267 | dbgs() << "~0U"; |
| 1268 | else |
| 1269 | dbgs() << Index; |
| 1270 | dbgs() << " => " << getAsString(Index) << " }\n"; |
| 1271 | } |
| 1272 | |
| 1273 | dbgs() << "]\n"; |
| 1274 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 1275 | #endif |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1276 | |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1277 | //===----------------------------------------------------------------------===// |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1278 | // AttrBuilder Method Implementations |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1279 | //===----------------------------------------------------------------------===// |
| 1280 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1281 | AttrBuilder::AttrBuilder(AttributeList AL, unsigned Index) { |
| 1282 | AttributeListImpl *pImpl = AL.pImpl; |
Bill Wendling | 096f544 | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 1283 | if (!pImpl) return; |
| 1284 | |
Amaury Sechet | 24c84fd | 2016-06-14 22:04:16 +0000 | [diff] [blame] | 1285 | for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) { |
Bill Wendling | 211316c | 2013-04-18 20:17:28 +0000 | [diff] [blame] | 1286 | if (pImpl->getSlotIndex(I) != Index) continue; |
Bill Wendling | 096f544 | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 1287 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1288 | for (AttributeListImpl::iterator II = pImpl->begin(I), IE = pImpl->end(I); |
| 1289 | II != IE; ++II) |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1290 | addAttribute(*II); |
Bill Wendling | 9eb689c | 2013-01-28 00:21:34 +0000 | [diff] [blame] | 1291 | |
| 1292 | break; |
| 1293 | } |
Bill Wendling | 096f544 | 2013-01-07 08:24:35 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
Reid Kleckner | c2cb560 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 1296 | AttrBuilder::AttrBuilder(AttributeSet AS) { |
| 1297 | if (AS.hasAttributes()) { |
| 1298 | for (const Attribute &A : AS) |
Reid Kleckner | eb9dd5b | 2017-04-10 23:31:05 +0000 | [diff] [blame] | 1299 | addAttribute(A); |
| 1300 | } |
| 1301 | } |
| 1302 | |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1303 | void AttrBuilder::clear() { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1304 | Attrs.reset(); |
Sanjoy Das | 88d0fde | 2015-09-03 22:27:42 +0000 | [diff] [blame] | 1305 | TargetDepAttrs.clear(); |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1306 | Alignment = StackAlignment = DerefBytes = DerefOrNullBytes = 0; |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1307 | AllocSizeArgs = 0; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1311 | assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!"); |
Bill Wendling | 1c7cc8a | 2013-01-31 23:16:25 +0000 | [diff] [blame] | 1312 | assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment && |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1313 | Val != Attribute::Dereferenceable && Val != Attribute::AllocSize && |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1314 | "Adding integer attribute without adding a value!"); |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1315 | Attrs[Val] = true; |
Bill Wendling | 7c04e04 | 2012-10-09 19:01:18 +0000 | [diff] [blame] | 1316 | return *this; |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1319 | AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) { |
Bill Wendling | 0a43730 | 2013-02-10 10:13:23 +0000 | [diff] [blame] | 1320 | if (Attr.isStringAttribute()) { |
| 1321 | addAttribute(Attr.getKindAsString(), Attr.getValueAsString()); |
| 1322 | return *this; |
| 1323 | } |
| 1324 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 1325 | Attribute::AttrKind Kind = Attr.getKindAsEnum(); |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1326 | Attrs[Kind] = true; |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1327 | |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 1328 | if (Kind == Attribute::Alignment) |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1329 | Alignment = Attr.getAlignment(); |
Bill Wendling | 3f12ac2 | 2013-02-05 22:37:24 +0000 | [diff] [blame] | 1330 | else if (Kind == Attribute::StackAlignment) |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1331 | StackAlignment = Attr.getStackAlignment(); |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1332 | else if (Kind == Attribute::Dereferenceable) |
| 1333 | DerefBytes = Attr.getDereferenceableBytes(); |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1334 | else if (Kind == Attribute::DereferenceableOrNull) |
| 1335 | DerefOrNullBytes = Attr.getDereferenceableOrNullBytes(); |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1336 | else if (Kind == Attribute::AllocSize) |
| 1337 | AllocSizeArgs = Attr.getValueAsInt(); |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1338 | return *this; |
| 1339 | } |
| 1340 | |
Bill Wendling | b9c5b1a | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 1341 | AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) { |
| 1342 | TargetDepAttrs[A] = V; |
| 1343 | return *this; |
| 1344 | } |
| 1345 | |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1346 | AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1347 | assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!"); |
| 1348 | Attrs[Val] = false; |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1349 | |
| 1350 | if (Val == Attribute::Alignment) |
| 1351 | Alignment = 0; |
| 1352 | else if (Val == Attribute::StackAlignment) |
| 1353 | StackAlignment = 0; |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1354 | else if (Val == Attribute::Dereferenceable) |
| 1355 | DerefBytes = 0; |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1356 | else if (Val == Attribute::DereferenceableOrNull) |
| 1357 | DerefOrNullBytes = 0; |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1358 | else if (Val == Attribute::AllocSize) |
| 1359 | AllocSizeArgs = 0; |
Bill Wendling | 23804da | 2013-01-31 23:38:01 +0000 | [diff] [blame] | 1360 | |
| 1361 | return *this; |
| 1362 | } |
| 1363 | |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1364 | AttrBuilder &AttrBuilder::removeAttributes(AttributeList A, uint64_t Index) { |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 1365 | remove(A.getAttributes(Index)); |
Bill Wendling | 1aa9d9e | 2013-01-28 05:23:28 +0000 | [diff] [blame] | 1366 | return *this; |
| 1367 | } |
| 1368 | |
Bill Wendling | b9c5b1a | 2013-02-05 08:09:32 +0000 | [diff] [blame] | 1369 | AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { |
| 1370 | std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A); |
| 1371 | if (I != TargetDepAttrs.end()) |
| 1372 | TargetDepAttrs.erase(I); |
| 1373 | return *this; |
| 1374 | } |
| 1375 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1376 | std::pair<unsigned, Optional<unsigned>> AttrBuilder::getAllocSizeArgs() const { |
| 1377 | return unpackAllocSizeArgs(AllocSizeArgs); |
| 1378 | } |
| 1379 | |
Bill Wendling | 50d2784 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1380 | AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) { |
Bill Wendling | abd5ba2 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 1381 | if (Align == 0) return *this; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1382 | |
Bill Wendling | abf3feb | 2012-10-05 06:44:41 +0000 | [diff] [blame] | 1383 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 1384 | assert(Align <= 0x40000000 && "Alignment too large."); |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1385 | |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1386 | Attrs[Attribute::Alignment] = true; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1387 | Alignment = Align; |
Bill Wendling | abd5ba2 | 2012-10-14 03:58:29 +0000 | [diff] [blame] | 1388 | return *this; |
Chris Lattner | 3e13b8c | 2008-01-02 23:42:30 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1391 | AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) { |
| 1392 | // Default alignment, allow the target to define how to align it. |
| 1393 | if (Align == 0) return *this; |
| 1394 | |
| 1395 | assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); |
| 1396 | assert(Align <= 0x100 && "Alignment too large."); |
| 1397 | |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1398 | Attrs[Attribute::StackAlignment] = true; |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1399 | StackAlignment = Align; |
| 1400 | return *this; |
| 1401 | } |
| 1402 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1403 | AttrBuilder &AttrBuilder::addDereferenceableAttr(uint64_t Bytes) { |
| 1404 | if (Bytes == 0) return *this; |
| 1405 | |
| 1406 | Attrs[Attribute::Dereferenceable] = true; |
| 1407 | DerefBytes = Bytes; |
| 1408 | return *this; |
| 1409 | } |
| 1410 | |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1411 | AttrBuilder &AttrBuilder::addDereferenceableOrNullAttr(uint64_t Bytes) { |
| 1412 | if (Bytes == 0) |
| 1413 | return *this; |
| 1414 | |
| 1415 | Attrs[Attribute::DereferenceableOrNull] = true; |
| 1416 | DerefOrNullBytes = Bytes; |
| 1417 | return *this; |
| 1418 | } |
| 1419 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1420 | AttrBuilder &AttrBuilder::addAllocSizeAttr(unsigned ElemSize, |
| 1421 | const Optional<unsigned> &NumElems) { |
| 1422 | return addAllocSizeAttrFromRawRepr(packAllocSizeArgs(ElemSize, NumElems)); |
| 1423 | } |
| 1424 | |
| 1425 | AttrBuilder &AttrBuilder::addAllocSizeAttrFromRawRepr(uint64_t RawArgs) { |
| 1426 | // (0, 0) is our "not present" value, so we need to check for it here. |
| 1427 | assert(RawArgs && "Invalid allocsize arguments -- given allocsize(0, 0)"); |
| 1428 | |
| 1429 | Attrs[Attribute::AllocSize] = true; |
| 1430 | // Reuse existing machinery to store this as a single 64-bit integer so we can |
| 1431 | // save a few bytes over using a pair<unsigned, Optional<unsigned>>. |
| 1432 | AllocSizeArgs = RawArgs; |
| 1433 | return *this; |
| 1434 | } |
| 1435 | |
Bill Wendling | e261492 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1436 | AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { |
| 1437 | // FIXME: What if both have alignments, but they don't match?! |
| 1438 | if (!Alignment) |
| 1439 | Alignment = B.Alignment; |
| 1440 | |
| 1441 | if (!StackAlignment) |
| 1442 | StackAlignment = B.StackAlignment; |
| 1443 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1444 | if (!DerefBytes) |
| 1445 | DerefBytes = B.DerefBytes; |
| 1446 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1447 | if (!DerefOrNullBytes) |
| 1448 | DerefOrNullBytes = B.DerefOrNullBytes; |
| 1449 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1450 | if (!AllocSizeArgs) |
| 1451 | AllocSizeArgs = B.AllocSizeArgs; |
| 1452 | |
Benjamin Kramer | 45e7d53 | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 1453 | Attrs |= B.Attrs; |
Bill Wendling | e261492 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1454 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1455 | for (auto I : B.td_attrs()) |
| 1456 | TargetDepAttrs[I.first] = I.second; |
Bill Wendling | e261492 | 2013-02-06 01:16:00 +0000 | [diff] [blame] | 1457 | |
| 1458 | return *this; |
| 1459 | } |
| 1460 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1461 | AttrBuilder &AttrBuilder::remove(const AttrBuilder &B) { |
| 1462 | // FIXME: What if both have alignments, but they don't match?! |
| 1463 | if (B.Alignment) |
| 1464 | Alignment = 0; |
| 1465 | |
| 1466 | if (B.StackAlignment) |
| 1467 | StackAlignment = 0; |
| 1468 | |
| 1469 | if (B.DerefBytes) |
| 1470 | DerefBytes = 0; |
| 1471 | |
| 1472 | if (B.DerefOrNullBytes) |
| 1473 | DerefOrNullBytes = 0; |
| 1474 | |
George Burgess IV | 278199f | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 1475 | if (B.AllocSizeArgs) |
| 1476 | AllocSizeArgs = 0; |
| 1477 | |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1478 | Attrs &= ~B.Attrs; |
| 1479 | |
| 1480 | for (auto I : B.td_attrs()) |
| 1481 | TargetDepAttrs.erase(I.first); |
| 1482 | |
| 1483 | return *this; |
| 1484 | } |
| 1485 | |
| 1486 | bool AttrBuilder::overlaps(const AttrBuilder &B) const { |
| 1487 | // First check if any of the target independent attributes overlap. |
| 1488 | if ((Attrs & B.Attrs).any()) |
| 1489 | return true; |
| 1490 | |
| 1491 | // Then check if any target dependent ones do. |
Sean Silva | 9011aca | 2017-02-22 06:34:04 +0000 | [diff] [blame] | 1492 | for (const auto &I : td_attrs()) |
Pete Cooper | d2a4461 | 2015-05-06 23:19:43 +0000 | [diff] [blame] | 1493 | if (B.contains(I.first)) |
| 1494 | return true; |
| 1495 | |
| 1496 | return false; |
| 1497 | } |
| 1498 | |
Bill Wendling | 4b00144 | 2013-02-06 01:33:42 +0000 | [diff] [blame] | 1499 | bool AttrBuilder::contains(StringRef A) const { |
| 1500 | return TargetDepAttrs.find(A) != TargetDepAttrs.end(); |
| 1501 | } |
| 1502 | |
Bill Wendling | 50d2784 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1503 | bool AttrBuilder::hasAttributes() const { |
Benjamin Kramer | eaf706b | 2013-02-18 12:09:51 +0000 | [diff] [blame] | 1504 | return !Attrs.none() || !TargetDepAttrs.empty(); |
Bill Wendling | c6daefa | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 1505 | } |
Bill Wendling | 9ac69f9 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 1506 | |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 1507 | bool AttrBuilder::hasAttributes(AttributeList AL, uint64_t Index) const { |
| 1508 | AttributeSet AS = AL.getAttributes(Index); |
Bill Wendling | 9ca01da | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1509 | |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 1510 | for (Attribute Attr : AS) { |
Hal Finkel | e15442c | 2014-07-18 06:51:55 +0000 | [diff] [blame] | 1511 | if (Attr.isEnumAttribute() || Attr.isIntAttribute()) { |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 1512 | if (contains(Attr.getKindAsEnum())) |
Bill Wendling | 7cde51d | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1513 | return true; |
| 1514 | } else { |
| 1515 | assert(Attr.isStringAttribute() && "Invalid attribute kind!"); |
Reid Kleckner | 6652a52 | 2017-04-28 18:37:16 +0000 | [diff] [blame] | 1516 | return contains(Attr.getKindAsString()); |
Bill Wendling | 7cde51d | 2013-02-12 07:56:49 +0000 | [diff] [blame] | 1517 | } |
| 1518 | } |
Bill Wendling | 9ca01da | 2013-02-02 00:42:06 +0000 | [diff] [blame] | 1519 | |
| 1520 | return false; |
Bill Wendling | 70f3917 | 2012-10-09 00:01:21 +0000 | [diff] [blame] | 1521 | } |
Bill Wendling | 9ac69f9 | 2013-01-04 20:54:35 +0000 | [diff] [blame] | 1522 | |
Bill Wendling | 50d2784 | 2012-10-15 20:35:56 +0000 | [diff] [blame] | 1523 | bool AttrBuilder::hasAlignmentAttr() const { |
Bill Wendling | cd33034 | 2013-01-04 23:27:34 +0000 | [diff] [blame] | 1524 | return Alignment != 0; |
Bill Wendling | c6daefa | 2012-10-08 23:27:46 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1527 | bool AttrBuilder::operator==(const AttrBuilder &B) { |
Benjamin Kramer | 45e7d53 | 2013-02-16 19:13:18 +0000 | [diff] [blame] | 1528 | if (Attrs != B.Attrs) |
| 1529 | return false; |
Bill Wendling | 4b00144 | 2013-02-06 01:33:42 +0000 | [diff] [blame] | 1530 | |
| 1531 | for (td_const_iterator I = TargetDepAttrs.begin(), |
| 1532 | E = TargetDepAttrs.end(); I != E; ++I) |
| 1533 | if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end()) |
| 1534 | return false; |
| 1535 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1536 | return Alignment == B.Alignment && StackAlignment == B.StackAlignment && |
| 1537 | DerefBytes == B.DerefBytes; |
Bill Wendling | d509a66 | 2013-01-29 00:34:06 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1540 | //===----------------------------------------------------------------------===// |
| 1541 | // AttributeFuncs Function Defintions |
| 1542 | //===----------------------------------------------------------------------===// |
| 1543 | |
Bill Wendling | c79cdff | 2013-02-01 01:04:27 +0000 | [diff] [blame] | 1544 | /// \brief Which attributes cannot be applied to a type. |
Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 1545 | AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) { |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1546 | AttrBuilder Incompatible; |
| 1547 | |
| 1548 | if (!Ty->isIntegerTy()) |
| 1549 | // Attribute that only apply to integers. |
| 1550 | Incompatible.addAttribute(Attribute::SExt) |
| 1551 | .addAttribute(Attribute::ZExt); |
| 1552 | |
| 1553 | if (!Ty->isPointerTy()) |
| 1554 | // Attribute that only apply to pointers. |
| 1555 | Incompatible.addAttribute(Attribute::ByVal) |
| 1556 | .addAttribute(Attribute::Nest) |
| 1557 | .addAttribute(Attribute::NoAlias) |
| 1558 | .addAttribute(Attribute::NoCapture) |
Nick Lewycky | d52b152 | 2014-05-20 01:23:40 +0000 | [diff] [blame] | 1559 | .addAttribute(Attribute::NonNull) |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 1560 | .addDereferenceableAttr(1) // the int here is ignored |
Sanjoy Das | 31ea6d1 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 1561 | .addDereferenceableOrNullAttr(1) // the int here is ignored |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 1562 | .addAttribute(Attribute::ReadNone) |
| 1563 | .addAttribute(Attribute::ReadOnly) |
Reid Kleckner | a534a38 | 2013-12-19 02:14:12 +0000 | [diff] [blame] | 1564 | .addAttribute(Attribute::StructRet) |
| 1565 | .addAttribute(Attribute::InAlloca); |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1566 | |
Pete Cooper | 2777d887 | 2015-05-06 23:19:56 +0000 | [diff] [blame] | 1567 | return Incompatible; |
Bill Wendling | 57625a4 | 2013-01-25 23:09:36 +0000 | [diff] [blame] | 1568 | } |
Akira Hatanaka | 1cb242e | 2015-12-22 23:57:37 +0000 | [diff] [blame] | 1569 | |
| 1570 | template<typename AttrClass> |
| 1571 | static bool isEqual(const Function &Caller, const Function &Callee) { |
| 1572 | return Caller.getFnAttribute(AttrClass::getKind()) == |
| 1573 | Callee.getFnAttribute(AttrClass::getKind()); |
| 1574 | } |
| 1575 | |
| 1576 | /// \brief Compute the logical AND of the attributes of the caller and the |
| 1577 | /// callee. |
| 1578 | /// |
| 1579 | /// This function sets the caller's attribute to false if the callee's attribute |
| 1580 | /// is false. |
| 1581 | template<typename AttrClass> |
| 1582 | static void setAND(Function &Caller, const Function &Callee) { |
| 1583 | if (AttrClass::isSet(Caller, AttrClass::getKind()) && |
| 1584 | !AttrClass::isSet(Callee, AttrClass::getKind())) |
| 1585 | AttrClass::set(Caller, AttrClass::getKind(), false); |
| 1586 | } |
| 1587 | |
| 1588 | /// \brief Compute the logical OR of the attributes of the caller and the |
| 1589 | /// callee. |
| 1590 | /// |
| 1591 | /// This function sets the caller's attribute to true if the callee's attribute |
| 1592 | /// is true. |
| 1593 | template<typename AttrClass> |
| 1594 | static void setOR(Function &Caller, const Function &Callee) { |
| 1595 | if (!AttrClass::isSet(Caller, AttrClass::getKind()) && |
| 1596 | AttrClass::isSet(Callee, AttrClass::getKind())) |
| 1597 | AttrClass::set(Caller, AttrClass::getKind(), true); |
| 1598 | } |
| 1599 | |
| 1600 | /// \brief If the inlined function had a higher stack protection level than the |
| 1601 | /// calling function, then bump up the caller's stack protection level. |
| 1602 | static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) { |
| 1603 | // If upgrading the SSP attribute, clear out the old SSP Attributes first. |
| 1604 | // Having multiple SSP attributes doesn't actually hurt, but it adds useless |
| 1605 | // clutter to the IR. |
Reid Kleckner | ee4930b | 2017-05-02 22:07:37 +0000 | [diff] [blame] | 1606 | AttrBuilder OldSSPAttr; |
| 1607 | OldSSPAttr.addAttribute(Attribute::StackProtect) |
| 1608 | .addAttribute(Attribute::StackProtectStrong) |
| 1609 | .addAttribute(Attribute::StackProtectReq); |
Akira Hatanaka | 1cb242e | 2015-12-22 23:57:37 +0000 | [diff] [blame] | 1610 | |
Evgeniy Stepanov | f17120a | 2016-04-11 22:27:48 +0000 | [diff] [blame] | 1611 | if (Callee.hasFnAttribute(Attribute::StackProtectReq)) { |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1612 | Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr); |
Akira Hatanaka | 1cb242e | 2015-12-22 23:57:37 +0000 | [diff] [blame] | 1613 | Caller.addFnAttr(Attribute::StackProtectReq); |
| 1614 | } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) && |
Akira Hatanaka | 1cb242e | 2015-12-22 23:57:37 +0000 | [diff] [blame] | 1615 | !Caller.hasFnAttribute(Attribute::StackProtectReq)) { |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1616 | Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr); |
Akira Hatanaka | 1cb242e | 2015-12-22 23:57:37 +0000 | [diff] [blame] | 1617 | Caller.addFnAttr(Attribute::StackProtectStrong); |
| 1618 | } else if (Callee.hasFnAttribute(Attribute::StackProtect) && |
Akira Hatanaka | 1cb242e | 2015-12-22 23:57:37 +0000 | [diff] [blame] | 1619 | !Caller.hasFnAttribute(Attribute::StackProtectReq) && |
| 1620 | !Caller.hasFnAttribute(Attribute::StackProtectStrong)) |
| 1621 | Caller.addFnAttr(Attribute::StackProtect); |
| 1622 | } |
| 1623 | |
| 1624 | #define GET_ATTR_COMPAT_FUNC |
| 1625 | #include "AttributesCompatFunc.inc" |
| 1626 | |
| 1627 | bool AttributeFuncs::areInlineCompatible(const Function &Caller, |
| 1628 | const Function &Callee) { |
| 1629 | return hasCompatibleFnAttrs(Caller, Callee); |
| 1630 | } |
| 1631 | |
Akira Hatanaka | 1cb242e | 2015-12-22 23:57:37 +0000 | [diff] [blame] | 1632 | void AttributeFuncs::mergeAttributesForInlining(Function &Caller, |
| 1633 | const Function &Callee) { |
| 1634 | mergeFnAttrs(Caller, Callee); |
| 1635 | } |