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