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