blob: f466d167e9724118f03e85595c98a8ce1410cc01 [file] [log] [blame]
Bill Wendlingec454542013-01-28 21:55:20 +00001//===-- Attributes.cpp - Implement AttributesList -------------------------===//
Chris Lattner3e13b8c2008-01-02 23:42:30 +00002//
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 Wendlingec454542013-01-28 21:55:20 +000010// \file
11// \brief This file implements the Attribute, AttributeImpl, AttrBuilder,
Bill Wendling6848e382012-12-19 22:42:22 +000012// AttributeSetImpl, and AttributeSet classes.
Chris Lattner3e13b8c2008-01-02 23:42:30 +000013//
14//===----------------------------------------------------------------------===//
15
Chandler Carruth9fb823b2013-01-02 11:36:10 +000016#include "llvm/IR/Attributes.h"
Bill Wendling4607f4b2012-12-20 01:36:59 +000017#include "AttributeImpl.h"
Bill Wendlinge38b8042012-09-26 21:07:29 +000018#include "LLVMContextImpl.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "llvm/ADT/StringExtras.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000020#include "llvm/IR/Type.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000021#include "llvm/Support/Atomic.h"
David Greenef7014732010-01-05 01:29:58 +000022#include "llvm/Support/Debug.h"
Chris Lattner3e13b8c2008-01-02 23:42:30 +000023#include "llvm/Support/ManagedStatic.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/Support/Mutex.h"
Benjamin Kramer1a25d732009-08-23 11:37:21 +000025#include "llvm/Support/raw_ostream.h"
Bill Wendlingd2e493b2013-01-24 00:06:56 +000026#include <algorithm>
Chris Lattner3e13b8c2008-01-02 23:42:30 +000027using namespace llvm;
28
Chris Lattner8a923e72008-03-12 17:45:29 +000029//===----------------------------------------------------------------------===//
Bill Wendling7707c5a2013-01-29 00:48:16 +000030// Attribute Construction Methods
Chris Lattner8a923e72008-03-12 17:45:29 +000031//===----------------------------------------------------------------------===//
Chris Lattnerd0e1f102008-01-03 00:10:22 +000032
Bill Wendling3f12ac22013-02-05 22:37:24 +000033Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
34 uint64_t Val) {
Bill Wendling73ea2de2012-10-08 21:47:17 +000035 LLVMContextImpl *pImpl = Context.pImpl;
36 FoldingSetNodeID ID;
Bill Wendling3f12ac22013-02-05 22:37:24 +000037 ID.AddInteger(Kind);
38 if (Val) ID.AddInteger(Val);
39
40 void *InsertPoint;
41 AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
42
43 if (!PA) {
44 // If we didn't find any existing attributes of the same shape then create a
45 // new one and insert it.
Benjamin Kramer741146b2013-07-11 12:13:16 +000046 if (!Val)
47 PA = new EnumAttributeImpl(Kind);
48 else
49 PA = new AlignAttributeImpl(Kind, Val);
Bill Wendling3f12ac22013-02-05 22:37:24 +000050 pImpl->AttrsSet.InsertNode(PA, InsertPoint);
51 }
52
53 // Return the Attribute that we found or created.
54 return Attribute(PA);
55}
56
57Attribute Attribute::get(LLVMContext &Context, StringRef Kind, StringRef Val) {
58 LLVMContextImpl *pImpl = Context.pImpl;
59 FoldingSetNodeID ID;
60 ID.AddString(Kind);
61 if (!Val.empty()) ID.AddString(Val);
Bill Wendling73ea2de2012-10-08 21:47:17 +000062
63 void *InsertPoint;
Bill Wendling4607f4b2012-12-20 01:36:59 +000064 AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
Bill Wendling73ea2de2012-10-08 21:47:17 +000065
66 if (!PA) {
67 // If we didn't find any existing attributes of the same shape then create a
68 // new one and insert it.
Benjamin Kramer741146b2013-07-11 12:13:16 +000069 PA = new StringAttributeImpl(Kind, Val);
Bill Wendling73ea2de2012-10-08 21:47:17 +000070 pImpl->AttrsSet.InsertNode(PA, InsertPoint);
71 }
72
Bill Wendlingb9c5b1a2013-02-05 08:09:32 +000073 // Return the Attribute that we found or created.
Bill Wendling3d7b0b82012-12-19 07:18:57 +000074 return Attribute(PA);
Bill Wendling73ea2de2012-10-08 21:47:17 +000075}
76
Bill Wendling4bbe9db2013-01-27 22:43:04 +000077Attribute Attribute::getWithAlignment(LLVMContext &Context, uint64_t Align) {
Bill Wendling1c7cc8a2013-01-31 23:16:25 +000078 assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
79 assert(Align <= 0x40000000 && "Alignment too large.");
Bill Wendling3f12ac22013-02-05 22:37:24 +000080 return get(Context, Alignment, Align);
Bill Wendling4bbe9db2013-01-27 22:43:04 +000081}
82
83Attribute Attribute::getWithStackAlignment(LLVMContext &Context,
84 uint64_t Align) {
Bill Wendling1c7cc8a2013-01-31 23:16:25 +000085 assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
86 assert(Align <= 0x100 && "Alignment too large.");
Bill Wendling3f12ac22013-02-05 22:37:24 +000087 return get(Context, StackAlignment, Align);
Bill Wendling4bbe9db2013-01-27 22:43:04 +000088}
89
Bill Wendling7707c5a2013-01-29 00:48:16 +000090//===----------------------------------------------------------------------===//
91// Attribute Accessor Methods
92//===----------------------------------------------------------------------===//
93
Bill Wendling3f12ac22013-02-05 22:37:24 +000094bool Attribute::isEnumAttribute() const {
95 return pImpl && pImpl->isEnumAttribute();
96}
97
98bool Attribute::isAlignAttribute() const {
99 return pImpl && pImpl->isAlignAttribute();
100}
101
102bool Attribute::isStringAttribute() const {
103 return pImpl && pImpl->isStringAttribute();
104}
105
106Attribute::AttrKind Attribute::getKindAsEnum() const {
Bill Wendling440e9d82013-07-25 00:34:29 +0000107 if (!pImpl) return None;
Bill Wendling3f12ac22013-02-05 22:37:24 +0000108 assert((isEnumAttribute() || isAlignAttribute()) &&
109 "Invalid attribute type to get the kind as an enum!");
110 return pImpl ? pImpl->getKindAsEnum() : None;
111}
112
113uint64_t Attribute::getValueAsInt() const {
Bill Wendling440e9d82013-07-25 00:34:29 +0000114 if (!pImpl) return 0;
Bill Wendling3f12ac22013-02-05 22:37:24 +0000115 assert(isAlignAttribute() &&
116 "Expected the attribute to be an alignment attribute!");
117 return pImpl ? pImpl->getValueAsInt() : 0;
118}
119
120StringRef Attribute::getKindAsString() const {
Bill Wendling440e9d82013-07-25 00:34:29 +0000121 if (!pImpl) return StringRef();
Bill Wendling3f12ac22013-02-05 22:37:24 +0000122 assert(isStringAttribute() &&
123 "Invalid attribute type to get the kind as a string!");
124 return pImpl ? pImpl->getKindAsString() : StringRef();
125}
126
127StringRef Attribute::getValueAsString() const {
Bill Wendling440e9d82013-07-25 00:34:29 +0000128 if (!pImpl) return StringRef();
Bill Wendling3f12ac22013-02-05 22:37:24 +0000129 assert(isStringAttribute() &&
130 "Invalid attribute type to get the value as a string!");
131 return pImpl ? pImpl->getValueAsString() : StringRef();
132}
133
Bill Wendlingae89a0f2013-02-05 23:48:36 +0000134bool Attribute::hasAttribute(AttrKind Kind) const {
135 return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None);
136}
137
138bool Attribute::hasAttribute(StringRef Kind) const {
139 if (!isStringAttribute()) return false;
140 return pImpl && pImpl->hasAttribute(Kind);
Bill Wendling03eefb32013-01-29 20:45:34 +0000141}
142
Bill Wendlingabf3feb2012-10-05 06:44:41 +0000143/// This returns the alignment field of an attribute as a byte alignment value.
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000144unsigned Attribute::getAlignment() const {
Bill Wendlingc79cdff2013-02-01 01:04:27 +0000145 assert(hasAttribute(Attribute::Alignment) &&
146 "Trying to get alignment from non-alignment attribute!");
Bill Wendling3f12ac22013-02-05 22:37:24 +0000147 return pImpl->getValueAsInt();
Bill Wendlingabf3feb2012-10-05 06:44:41 +0000148}
149
150/// This returns the stack alignment field of an attribute as a byte alignment
151/// value.
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000152unsigned Attribute::getStackAlignment() const {
Bill Wendlingc79cdff2013-02-01 01:04:27 +0000153 assert(hasAttribute(Attribute::StackAlignment) &&
154 "Trying to get alignment from non-alignment attribute!");
Bill Wendling3f12ac22013-02-05 22:37:24 +0000155 return pImpl->getValueAsInt();
Bill Wendlingabf3feb2012-10-05 06:44:41 +0000156}
157
Bill Wendling829b4782013-02-11 08:43:33 +0000158std::string Attribute::getAsString(bool InAttrGrp) const {
Bill Wendling9c2eba92013-01-31 20:59:05 +0000159 if (!pImpl) return "";
160
Kostya Serebryanycf880b92013-02-26 06:58:09 +0000161 if (hasAttribute(Attribute::SanitizeAddress))
162 return "sanitize_address";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000163 if (hasAttribute(Attribute::AlwaysInline))
164 return "alwaysinline";
Michael Gottesman41748d72013-06-27 00:25:01 +0000165 if (hasAttribute(Attribute::Builtin))
166 return "builtin";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000167 if (hasAttribute(Attribute::ByVal))
168 return "byval";
169 if (hasAttribute(Attribute::InlineHint))
170 return "inlinehint";
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000171 if (hasAttribute(Attribute::InReg))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000172 return "inreg";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000173 if (hasAttribute(Attribute::MinSize))
174 return "minsize";
175 if (hasAttribute(Attribute::Naked))
176 return "naked";
177 if (hasAttribute(Attribute::Nest))
178 return "nest";
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000179 if (hasAttribute(Attribute::NoAlias))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000180 return "noalias";
Bill Wendling09bd1f72013-02-22 00:12:35 +0000181 if (hasAttribute(Attribute::NoBuiltin))
182 return "nobuiltin";
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000183 if (hasAttribute(Attribute::NoCapture))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000184 return "nocapture";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000185 if (hasAttribute(Attribute::NoDuplicate))
186 return "noduplicate";
187 if (hasAttribute(Attribute::NoImplicitFloat))
188 return "noimplicitfloat";
189 if (hasAttribute(Attribute::NoInline))
190 return "noinline";
191 if (hasAttribute(Attribute::NonLazyBind))
192 return "nonlazybind";
193 if (hasAttribute(Attribute::NoRedZone))
194 return "noredzone";
195 if (hasAttribute(Attribute::NoReturn))
196 return "noreturn";
197 if (hasAttribute(Attribute::NoUnwind))
198 return "nounwind";
199 if (hasAttribute(Attribute::OptimizeForSize))
200 return "optsize";
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000201 if (hasAttribute(Attribute::ReadNone))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000202 return "readnone";
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000203 if (hasAttribute(Attribute::ReadOnly))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000204 return "readonly";
Stephen Linb8bd2322013-04-20 05:14:40 +0000205 if (hasAttribute(Attribute::Returned))
206 return "returned";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000207 if (hasAttribute(Attribute::ReturnsTwice))
208 return "returns_twice";
209 if (hasAttribute(Attribute::SExt))
210 return "signext";
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000211 if (hasAttribute(Attribute::StackProtect))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000212 return "ssp";
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000213 if (hasAttribute(Attribute::StackProtectReq))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000214 return "sspreq";
Bill Wendlingd154e2832013-01-23 06:41:41 +0000215 if (hasAttribute(Attribute::StackProtectStrong))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000216 return "sspstrong";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000217 if (hasAttribute(Attribute::StructRet))
218 return "sret";
Kostya Serebryanycf880b92013-02-26 06:58:09 +0000219 if (hasAttribute(Attribute::SanitizeThread))
220 return "sanitize_thread";
221 if (hasAttribute(Attribute::SanitizeMemory))
222 return "sanitize_memory";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000223 if (hasAttribute(Attribute::UWTable))
224 return "uwtable";
225 if (hasAttribute(Attribute::ZExt))
226 return "zeroext";
Diego Novilloc6399532013-05-24 12:26:52 +0000227 if (hasAttribute(Attribute::Cold))
228 return "cold";
Bill Wendling9c2eba92013-01-31 20:59:05 +0000229
230 // FIXME: These should be output like this:
231 //
232 // align=4
233 // alignstack=8
234 //
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000235 if (hasAttribute(Attribute::Alignment)) {
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000236 std::string Result;
Bill Wendling829b4782013-02-11 08:43:33 +0000237 Result += "align";
238 Result += (InAttrGrp) ? "=" : " ";
Bill Wendling3f12ac22013-02-05 22:37:24 +0000239 Result += utostr(getValueAsInt());
240 return Result;
241 }
Bill Wendling829b4782013-02-11 08:43:33 +0000242
Bill Wendling3f12ac22013-02-05 22:37:24 +0000243 if (hasAttribute(Attribute::StackAlignment)) {
244 std::string Result;
Bill Wendling829b4782013-02-11 08:43:33 +0000245 Result += "alignstack";
246 if (InAttrGrp) {
247 Result += "=";
248 Result += utostr(getValueAsInt());
249 } else {
250 Result += "(";
251 Result += utostr(getValueAsInt());
252 Result += ")";
253 }
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000254 return Result;
Dale Johannesen11a555e2008-02-19 23:51:49 +0000255 }
Bill Wendling9c2eba92013-01-31 20:59:05 +0000256
257 // Convert target-dependent attributes to strings of the form:
258 //
259 // "kind"
260 // "kind" = "value"
Bill Wendling9c2eba92013-01-31 20:59:05 +0000261 //
Bill Wendling3f12ac22013-02-05 22:37:24 +0000262 if (isStringAttribute()) {
Bill Wendling9c2eba92013-01-31 20:59:05 +0000263 std::string Result;
Bill Wendling3f12ac22013-02-05 22:37:24 +0000264 Result += '\"' + getKindAsString().str() + '"';
Bill Wendling9c2eba92013-01-31 20:59:05 +0000265
Bill Wendling3f12ac22013-02-05 22:37:24 +0000266 StringRef Val = pImpl->getValueAsString();
267 if (Val.empty()) return Result;
Bill Wendling7a33f772013-02-01 22:32:30 +0000268
Bill Wendling829b4782013-02-11 08:43:33 +0000269 Result += "=\"" + Val.str() + '"';
Bill Wendlingc79cdff2013-02-01 01:04:27 +0000270 return Result;
Bill Wendling9c2eba92013-01-31 20:59:05 +0000271 }
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000272
273 llvm_unreachable("Unknown attribute");
Chris Lattner3e13b8c2008-01-02 23:42:30 +0000274}
275
Bill Wendlingd509a662013-01-29 00:34:06 +0000276bool Attribute::operator<(Attribute A) const {
277 if (!pImpl && !A.pImpl) return false;
278 if (!pImpl) return true;
279 if (!A.pImpl) return false;
280 return *pImpl < *A.pImpl;
281}
282
Bill Wendlingd509a662013-01-29 00:34:06 +0000283//===----------------------------------------------------------------------===//
284// AttributeImpl Definition
285//===----------------------------------------------------------------------===//
286
Benjamin Kramer741146b2013-07-11 12:13:16 +0000287AttributeImpl::~AttributeImpl() {}
Bill Wendling3f12ac22013-02-05 22:37:24 +0000288
Bill Wendlingd509a662013-01-29 00:34:06 +0000289bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
Bill Wendling3f12ac22013-02-05 22:37:24 +0000290 if (isStringAttribute()) return false;
291 return getKindAsEnum() == A;
Bill Wendlingd509a662013-01-29 00:34:06 +0000292}
293
Bill Wendling3f12ac22013-02-05 22:37:24 +0000294bool AttributeImpl::hasAttribute(StringRef Kind) const {
295 if (!isStringAttribute()) return false;
296 return getKindAsString() == Kind;
Bill Wendlingd509a662013-01-29 00:34:06 +0000297}
298
Bill Wendling3f12ac22013-02-05 22:37:24 +0000299Attribute::AttrKind AttributeImpl::getKindAsEnum() const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000300 assert(isEnumAttribute() || isAlignAttribute());
301 return static_cast<const EnumAttributeImpl *>(this)->getEnumKind();
Bill Wendlingd509a662013-01-29 00:34:06 +0000302}
303
Bill Wendling3f12ac22013-02-05 22:37:24 +0000304uint64_t AttributeImpl::getValueAsInt() const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000305 assert(isAlignAttribute());
306 return static_cast<const AlignAttributeImpl *>(this)->getAlignment();
Bill Wendlingd509a662013-01-29 00:34:06 +0000307}
308
Bill Wendling3f12ac22013-02-05 22:37:24 +0000309StringRef AttributeImpl::getKindAsString() const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000310 assert(isStringAttribute());
311 return static_cast<const StringAttributeImpl *>(this)->getStringKind();
Bill Wendlingd509a662013-01-29 00:34:06 +0000312}
313
Bill Wendling3f12ac22013-02-05 22:37:24 +0000314StringRef AttributeImpl::getValueAsString() const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000315 assert(isStringAttribute());
316 return static_cast<const StringAttributeImpl *>(this)->getStringValue();
Bill Wendlingd509a662013-01-29 00:34:06 +0000317}
318
319bool AttributeImpl::operator<(const AttributeImpl &AI) const {
Bill Wendlingc79cdff2013-02-01 01:04:27 +0000320 // This sorts the attributes with Attribute::AttrKinds coming first (sorted
321 // relative to their enum value) and then strings.
Bill Wendling26b95752013-02-15 05:25:26 +0000322 if (isEnumAttribute()) {
323 if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum();
324 if (AI.isAlignAttribute()) return true;
325 if (AI.isStringAttribute()) return true;
326 }
Bill Wendlingc79cdff2013-02-01 01:04:27 +0000327
Bill Wendling3f12ac22013-02-05 22:37:24 +0000328 if (isAlignAttribute()) {
Bill Wendling26b95752013-02-15 05:25:26 +0000329 if (AI.isEnumAttribute()) return false;
330 if (AI.isAlignAttribute()) return getValueAsInt() < AI.getValueAsInt();
331 if (AI.isStringAttribute()) return true;
Bill Wendling3f12ac22013-02-05 22:37:24 +0000332 }
Bill Wendlingd509a662013-01-29 00:34:06 +0000333
Bill Wendling26b95752013-02-15 05:25:26 +0000334 if (AI.isEnumAttribute()) return false;
335 if (AI.isAlignAttribute()) return false;
336 if (getKindAsString() == AI.getKindAsString())
337 return getValueAsString() < AI.getValueAsString();
338 return getKindAsString() < AI.getKindAsString();
Bill Wendlingd509a662013-01-29 00:34:06 +0000339}
340
Bill Wendlingd509a662013-01-29 00:34:06 +0000341uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
342 // FIXME: Remove this.
343 switch (Val) {
344 case Attribute::EndAttrKinds:
Bill Wendlingd509a662013-01-29 00:34:06 +0000345 llvm_unreachable("Synthetic enumerators which should never get here");
346
347 case Attribute::None: return 0;
348 case Attribute::ZExt: return 1 << 0;
349 case Attribute::SExt: return 1 << 1;
350 case Attribute::NoReturn: return 1 << 2;
351 case Attribute::InReg: return 1 << 3;
352 case Attribute::StructRet: return 1 << 4;
353 case Attribute::NoUnwind: return 1 << 5;
354 case Attribute::NoAlias: return 1 << 6;
355 case Attribute::ByVal: return 1 << 7;
356 case Attribute::Nest: return 1 << 8;
357 case Attribute::ReadNone: return 1 << 9;
358 case Attribute::ReadOnly: return 1 << 10;
359 case Attribute::NoInline: return 1 << 11;
360 case Attribute::AlwaysInline: return 1 << 12;
361 case Attribute::OptimizeForSize: return 1 << 13;
362 case Attribute::StackProtect: return 1 << 14;
363 case Attribute::StackProtectReq: return 1 << 15;
364 case Attribute::Alignment: return 31 << 16;
365 case Attribute::NoCapture: return 1 << 21;
366 case Attribute::NoRedZone: return 1 << 22;
367 case Attribute::NoImplicitFloat: return 1 << 23;
368 case Attribute::Naked: return 1 << 24;
369 case Attribute::InlineHint: return 1 << 25;
370 case Attribute::StackAlignment: return 7 << 26;
371 case Attribute::ReturnsTwice: return 1 << 29;
372 case Attribute::UWTable: return 1 << 30;
373 case Attribute::NonLazyBind: return 1U << 31;
Kostya Serebryanycf880b92013-02-26 06:58:09 +0000374 case Attribute::SanitizeAddress: return 1ULL << 32;
Bill Wendlingd509a662013-01-29 00:34:06 +0000375 case Attribute::MinSize: return 1ULL << 33;
376 case Attribute::NoDuplicate: return 1ULL << 34;
377 case Attribute::StackProtectStrong: return 1ULL << 35;
Kostya Serebryanycf880b92013-02-26 06:58:09 +0000378 case Attribute::SanitizeThread: return 1ULL << 36;
379 case Attribute::SanitizeMemory: return 1ULL << 37;
Bill Wendling7bfdfe72013-02-22 00:40:12 +0000380 case Attribute::NoBuiltin: return 1ULL << 38;
Stephen Linb8bd2322013-04-20 05:14:40 +0000381 case Attribute::Returned: return 1ULL << 39;
Diego Novilloc6399532013-05-24 12:26:52 +0000382 case Attribute::Cold: return 1ULL << 40;
Michael Gottesman41748d72013-06-27 00:25:01 +0000383 case Attribute::Builtin: return 1ULL << 41;
Bill Wendling25342e12013-02-22 00:50:09 +0000384 }
385 llvm_unreachable("Unsupported attribute type");
Bill Wendlingd509a662013-01-29 00:34:06 +0000386}
387
388//===----------------------------------------------------------------------===//
389// AttributeSetNode Definition
390//===----------------------------------------------------------------------===//
391
392AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
393 ArrayRef<Attribute> Attrs) {
394 if (Attrs.empty())
395 return 0;
396
397 // Otherwise, build a key to look up the existing attributes.
398 LLVMContextImpl *pImpl = C.pImpl;
399 FoldingSetNodeID ID;
400
401 SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
Bill Wendling82c2ee62013-02-13 09:26:26 +0000402 array_pod_sort(SortedAttrs.begin(), SortedAttrs.end());
Bill Wendlingd509a662013-01-29 00:34:06 +0000403
404 for (SmallVectorImpl<Attribute>::iterator I = SortedAttrs.begin(),
405 E = SortedAttrs.end(); I != E; ++I)
406 I->Profile(ID);
407
408 void *InsertPoint;
409 AttributeSetNode *PA =
410 pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint);
411
412 // If we didn't find any existing attributes of the same shape then create a
413 // new one and insert it.
414 if (!PA) {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000415 // Coallocate entries after the AttributeSetNode itself.
416 void *Mem = ::operator new(sizeof(AttributeSetNode) +
417 sizeof(Attribute) * SortedAttrs.size());
418 PA = new (Mem) AttributeSetNode(SortedAttrs);
Bill Wendlingd509a662013-01-29 00:34:06 +0000419 pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
420 }
421
422 // Return the AttributesListNode that we found or created.
423 return PA;
424}
425
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000426bool AttributeSetNode::hasAttribute(Attribute::AttrKind Kind) const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000427 for (iterator I = begin(), E = end(); I != E; ++I)
NAKAMURA Takumib0944392013-01-31 03:47:28 +0000428 if (I->hasAttribute(Kind))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000429 return true;
430 return false;
431}
432
Bill Wendlingbce7b972013-02-13 08:42:21 +0000433bool AttributeSetNode::hasAttribute(StringRef Kind) const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000434 for (iterator I = begin(), E = end(); I != E; ++I)
Bill Wendlingbce7b972013-02-13 08:42:21 +0000435 if (I->hasAttribute(Kind))
436 return true;
437 return false;
438}
439
440Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000441 for (iterator I = begin(), E = end(); I != E; ++I)
Bill Wendlingbce7b972013-02-13 08:42:21 +0000442 if (I->hasAttribute(Kind))
443 return *I;
444 return Attribute();
445}
446
447Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000448 for (iterator I = begin(), E = end(); I != E; ++I)
Bill Wendlingbce7b972013-02-13 08:42:21 +0000449 if (I->hasAttribute(Kind))
450 return *I;
451 return Attribute();
452}
453
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000454unsigned AttributeSetNode::getAlignment() const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000455 for (iterator I = begin(), E = end(); I != E; ++I)
NAKAMURA Takumib0944392013-01-31 03:47:28 +0000456 if (I->hasAttribute(Attribute::Alignment))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000457 return I->getAlignment();
458 return 0;
459}
460
461unsigned AttributeSetNode::getStackAlignment() const {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000462 for (iterator I = begin(), E = end(); I != E; ++I)
NAKAMURA Takumib0944392013-01-31 03:47:28 +0000463 if (I->hasAttribute(Attribute::StackAlignment))
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000464 return I->getStackAlignment();
465 return 0;
466}
467
Rafael Espindolacbf5a7a2013-05-01 13:07:03 +0000468std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
Benjamin Kramer0baf8f42013-04-19 11:43:21 +0000469 std::string Str;
Benjamin Kramer741146b2013-07-11 12:13:16 +0000470 for (iterator I = begin(), E = end(); I != E; ++I) {
471 if (I != begin())
Rafael Espindolacbf5a7a2013-05-01 13:07:03 +0000472 Str += ' ';
473 Str += I->getAsString(InAttrGrp);
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000474 }
475 return Str;
476}
477
Bill Wendlingd509a662013-01-29 00:34:06 +0000478//===----------------------------------------------------------------------===//
479// AttributeSetImpl Definition
480//===----------------------------------------------------------------------===//
481
Rafael Espindoladd275302013-04-30 16:53:38 +0000482uint64_t AttributeSetImpl::Raw(unsigned Index) const {
Bill Wendlingd509a662013-01-29 00:34:06 +0000483 for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) {
484 if (getSlotIndex(I) != Index) continue;
Benjamin Kramer741146b2013-07-11 12:13:16 +0000485 const AttributeSetNode *ASN = getSlotNode(I);
Bill Wendling91226182013-02-02 00:52:44 +0000486 uint64_t Mask = 0;
Bill Wendlingd509a662013-01-29 00:34:06 +0000487
Benjamin Kramer741146b2013-07-11 12:13:16 +0000488 for (AttributeSetNode::iterator II = ASN->begin(),
Bill Wendling91226182013-02-02 00:52:44 +0000489 IE = ASN->end(); II != IE; ++II) {
490 Attribute Attr = *II;
Bill Wendlingd746e402013-02-10 23:18:05 +0000491
492 // This cannot handle string attributes.
493 if (Attr.isStringAttribute()) continue;
494
Bill Wendling3f12ac22013-02-05 22:37:24 +0000495 Attribute::AttrKind Kind = Attr.getKindAsEnum();
Bill Wendling91226182013-02-02 00:52:44 +0000496
Bill Wendling3f12ac22013-02-05 22:37:24 +0000497 if (Kind == Attribute::Alignment)
Bill Wendling91226182013-02-02 00:52:44 +0000498 Mask |= (Log2_32(ASN->getAlignment()) + 1) << 16;
Bill Wendling3f12ac22013-02-05 22:37:24 +0000499 else if (Kind == Attribute::StackAlignment)
Bill Wendling91226182013-02-02 00:52:44 +0000500 Mask |= (Log2_32(ASN->getStackAlignment()) + 1) << 26;
501 else
Bill Wendling3f12ac22013-02-05 22:37:24 +0000502 Mask |= AttributeImpl::getAttrMask(Kind);
Bill Wendling91226182013-02-02 00:52:44 +0000503 }
504
505 return Mask;
Bill Wendlingd509a662013-01-29 00:34:06 +0000506 }
507
508 return 0;
509}
510
Peter Collingbourneabca2ec2013-08-02 22:34:30 +0000511void AttributeSetImpl::dump() const {
512 AttributeSet(const_cast<AttributeSetImpl *>(this)).dump();
513}
514
Bill Wendlingd509a662013-01-29 00:34:06 +0000515//===----------------------------------------------------------------------===//
516// AttributeSet Construction and Mutation Methods
517//===----------------------------------------------------------------------===//
518
Bill Wendling60011b82013-01-29 01:43:29 +0000519AttributeSet
520AttributeSet::getImpl(LLVMContext &C,
521 ArrayRef<std::pair<unsigned, AttributeSetNode*> > Attrs) {
Bill Wendlingd509a662013-01-29 00:34:06 +0000522 LLVMContextImpl *pImpl = C.pImpl;
523 FoldingSetNodeID ID;
524 AttributeSetImpl::Profile(ID, Attrs);
525
526 void *InsertPoint;
527 AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
528
529 // If we didn't find any existing attributes of the same shape then
530 // create a new one and insert it.
531 if (!PA) {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000532 // Coallocate entries after the AttributeSetImpl itself.
533 void *Mem = ::operator new(sizeof(AttributeSetImpl) +
534 sizeof(std::pair<unsigned, AttributeSetNode *>) *
535 Attrs.size());
536 PA = new (Mem) AttributeSetImpl(C, Attrs);
Bill Wendlingd509a662013-01-29 00:34:06 +0000537 pImpl->AttrsLists.InsertNode(PA, InsertPoint);
538 }
539
540 // Return the AttributesList that we found or created.
541 return AttributeSet(PA);
542}
543
544AttributeSet AttributeSet::get(LLVMContext &C,
545 ArrayRef<std::pair<unsigned, Attribute> > Attrs){
546 // If there are no attributes then return a null AttributesList pointer.
547 if (Attrs.empty())
548 return AttributeSet();
549
550#ifndef NDEBUG
551 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
552 assert((!i || Attrs[i-1].first <= Attrs[i].first) &&
553 "Misordered Attributes list!");
Bill Wendling3f12ac22013-02-05 22:37:24 +0000554 assert(!Attrs[i].second.hasAttribute(Attribute::None) &&
Bill Wendlingd509a662013-01-29 00:34:06 +0000555 "Pointless attribute!");
556 }
557#endif
558
559 // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
560 // list.
561 SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrPairVec;
562 for (ArrayRef<std::pair<unsigned, Attribute> >::iterator I = Attrs.begin(),
563 E = Attrs.end(); I != E; ) {
564 unsigned Index = I->first;
565 SmallVector<Attribute, 4> AttrVec;
NAKAMURA Takumif05d2f22013-01-29 15:18:16 +0000566 while (I != E && I->first == Index) {
Bill Wendlingd509a662013-01-29 00:34:06 +0000567 AttrVec.push_back(I->second);
568 ++I;
569 }
570
571 AttrPairVec.push_back(std::make_pair(Index,
572 AttributeSetNode::get(C, AttrVec)));
573 }
574
575 return getImpl(C, AttrPairVec);
576}
577
578AttributeSet AttributeSet::get(LLVMContext &C,
579 ArrayRef<std::pair<unsigned,
580 AttributeSetNode*> > Attrs) {
581 // If there are no attributes then return a null AttributesList pointer.
582 if (Attrs.empty())
583 return AttributeSet();
584
585 return getImpl(C, Attrs);
586}
587
Bill Wendling211316c2013-04-18 20:17:28 +0000588AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, AttrBuilder &B) {
Bill Wendlingd509a662013-01-29 00:34:06 +0000589 if (!B.hasAttributes())
590 return AttributeSet();
Bill Wendlingf7134812013-01-29 01:02:03 +0000591
Bill Wendlingae89a0f2013-02-05 23:48:36 +0000592 // Add target-independent attributes.
Bill Wendlingf7134812013-01-29 01:02:03 +0000593 SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
Benjamin Kramer45e7d532013-02-16 19:13:18 +0000594 for (Attribute::AttrKind Kind = Attribute::None;
Benjamin Kramer6f37dac2013-02-16 19:22:28 +0000595 Kind != Attribute::EndAttrKinds; Kind = Attribute::AttrKind(Kind + 1)) {
Benjamin Kramer45e7d532013-02-16 19:13:18 +0000596 if (!B.contains(Kind))
597 continue;
598
Bill Wendlingf7134812013-01-29 01:02:03 +0000599 if (Kind == Attribute::Alignment)
Bill Wendling211316c2013-04-18 20:17:28 +0000600 Attrs.push_back(std::make_pair(Index, Attribute::
Bill Wendlingf7134812013-01-29 01:02:03 +0000601 getWithAlignment(C, B.getAlignment())));
602 else if (Kind == Attribute::StackAlignment)
Bill Wendling211316c2013-04-18 20:17:28 +0000603 Attrs.push_back(std::make_pair(Index, Attribute::
Bill Wendlingf7134812013-01-29 01:02:03 +0000604 getWithStackAlignment(C, B.getStackAlignment())));
605 else
Bill Wendling211316c2013-04-18 20:17:28 +0000606 Attrs.push_back(std::make_pair(Index, Attribute::get(C, Kind)));
Bill Wendlingf7134812013-01-29 01:02:03 +0000607 }
608
Bill Wendlingae89a0f2013-02-05 23:48:36 +0000609 // Add target-dependent (string) attributes.
610 for (AttrBuilder::td_iterator I = B.td_begin(), E = B.td_end();
611 I != E; ++I)
Bill Wendling211316c2013-04-18 20:17:28 +0000612 Attrs.push_back(std::make_pair(Index, Attribute::get(C, I->first,I->second)));
Bill Wendlingae89a0f2013-02-05 23:48:36 +0000613
Bill Wendlingf7134812013-01-29 01:02:03 +0000614 return get(C, Attrs);
Bill Wendlingd509a662013-01-29 00:34:06 +0000615}
616
Bill Wendling211316c2013-04-18 20:17:28 +0000617AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
Bill Wendlingd509a662013-01-29 00:34:06 +0000618 ArrayRef<Attribute::AttrKind> Kind) {
619 SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
620 for (ArrayRef<Attribute::AttrKind>::iterator I = Kind.begin(),
621 E = Kind.end(); I != E; ++I)
Bill Wendling211316c2013-04-18 20:17:28 +0000622 Attrs.push_back(std::make_pair(Index, Attribute::get(C, *I)));
Bill Wendlingd509a662013-01-29 00:34:06 +0000623 return get(C, Attrs);
624}
625
626AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) {
627 if (Attrs.empty()) return AttributeSet();
Peter Collingbournebd6c7452013-08-02 22:29:40 +0000628 if (Attrs.size() == 1) return Attrs[0];
Bill Wendlingd509a662013-01-29 00:34:06 +0000629
630 SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrNodeVec;
Peter Collingbournebd6c7452013-08-02 22:29:40 +0000631 AttributeSetImpl *A0 = Attrs[0].pImpl;
632 if (A0)
633 AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumAttributes()));
634 // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec
635 // ordered by index. Because we know that each list in Attrs is ordered by
636 // index we only need to merge each successive list in rather than doing a
637 // full sort.
638 for (unsigned I = 1, E = Attrs.size(); I != E; ++I) {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000639 AttributeSetImpl *AS = Attrs[I].pImpl;
640 if (!AS) continue;
Peter Collingbournebd6c7452013-08-02 22:29:40 +0000641 SmallVector<std::pair<unsigned, AttributeSetNode *>, 8>::iterator
642 ANVI = AttrNodeVec.begin(), ANVE;
643 for (const AttributeSetImpl::IndexAttrPair
644 *AI = AS->getNode(0),
645 *AE = AS->getNode(AS->getNumAttributes());
646 AI != AE; ++AI) {
647 ANVE = AttrNodeVec.end();
648 while (ANVI != ANVE && ANVI->first <= AI->first)
649 ++ANVI;
650 ANVI = AttrNodeVec.insert(ANVI, *AI) + 1;
651 }
Bill Wendlingd509a662013-01-29 00:34:06 +0000652 }
653
654 return getImpl(C, AttrNodeVec);
655}
656
Bill Wendling211316c2013-04-18 20:17:28 +0000657AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
Bill Wendlingd509a662013-01-29 00:34:06 +0000658 Attribute::AttrKind Attr) const {
Bill Wendling211316c2013-04-18 20:17:28 +0000659 if (hasAttribute(Index, Attr)) return *this;
660 return addAttributes(C, Index, AttributeSet::get(C, Index, Attr));
Bill Wendlingd509a662013-01-29 00:34:06 +0000661}
662
Bill Wendling211316c2013-04-18 20:17:28 +0000663AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
Reed Kotler795c7b42013-03-13 20:20:08 +0000664 StringRef Kind) const {
665 llvm::AttrBuilder B;
666 B.addAttribute(Kind);
Bill Wendling211316c2013-04-18 20:17:28 +0000667 return addAttributes(C, Index, AttributeSet::get(C, Index, B));
Reed Kotler795c7b42013-03-13 20:20:08 +0000668}
669
Bill Wendling3b2f6102013-07-25 18:34:24 +0000670AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
671 StringRef Kind, StringRef Value) const {
672 llvm::AttrBuilder B;
673 B.addAttribute(Kind, Value);
674 return addAttributes(C, Index, AttributeSet::get(C, Index, B));
675}
676
Bill Wendling211316c2013-04-18 20:17:28 +0000677AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Index,
Bill Wendlingd509a662013-01-29 00:34:06 +0000678 AttributeSet Attrs) const {
679 if (!pImpl) return Attrs;
680 if (!Attrs.pImpl) return *this;
681
682#ifndef NDEBUG
683 // FIXME it is not obvious how this should work for alignment. For now, say
684 // we can't change a known alignment.
Bill Wendling211316c2013-04-18 20:17:28 +0000685 unsigned OldAlign = getParamAlignment(Index);
686 unsigned NewAlign = Attrs.getParamAlignment(Index);
Bill Wendlingd509a662013-01-29 00:34:06 +0000687 assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
688 "Attempt to change alignment!");
689#endif
690
691 // Add the attribute slots before the one we're trying to add.
692 SmallVector<AttributeSet, 4> AttrSet;
693 uint64_t NumAttrs = pImpl->getNumAttributes();
694 AttributeSet AS;
695 uint64_t LastIndex = 0;
696 for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
Bill Wendling211316c2013-04-18 20:17:28 +0000697 if (getSlotIndex(I) >= Index) {
698 if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
Bill Wendlingd509a662013-01-29 00:34:06 +0000699 break;
700 }
701 LastIndex = I + 1;
702 AttrSet.push_back(getSlotAttributes(I));
703 }
704
705 // Now add the attribute into the correct slot. There may already be an
706 // AttributeSet there.
Bill Wendling211316c2013-04-18 20:17:28 +0000707 AttrBuilder B(AS, Index);
Bill Wendlingd509a662013-01-29 00:34:06 +0000708
709 for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
Bill Wendling211316c2013-04-18 20:17:28 +0000710 if (Attrs.getSlotIndex(I) == Index) {
Benjamin Kramer741146b2013-07-11 12:13:16 +0000711 for (AttributeSetImpl::iterator II = Attrs.pImpl->begin(I),
Bill Wendlingd509a662013-01-29 00:34:06 +0000712 IE = Attrs.pImpl->end(I); II != IE; ++II)
Bill Wendling23804da2013-01-31 23:38:01 +0000713 B.addAttribute(*II);
Bill Wendlingd509a662013-01-29 00:34:06 +0000714 break;
715 }
716
Bill Wendling211316c2013-04-18 20:17:28 +0000717 AttrSet.push_back(AttributeSet::get(C, Index, B));
Bill Wendlingd509a662013-01-29 00:34:06 +0000718
719 // Add the remaining attribute slots.
720 for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
721 AttrSet.push_back(getSlotAttributes(I));
722
723 return get(C, AttrSet);
724}
725
Bill Wendling211316c2013-04-18 20:17:28 +0000726AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index,
Bill Wendlingd509a662013-01-29 00:34:06 +0000727 Attribute::AttrKind Attr) const {
Bill Wendling211316c2013-04-18 20:17:28 +0000728 if (!hasAttribute(Index, Attr)) return *this;
729 return removeAttributes(C, Index, AttributeSet::get(C, Index, Attr));
Bill Wendlingd509a662013-01-29 00:34:06 +0000730}
731
Bill Wendling211316c2013-04-18 20:17:28 +0000732AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index,
Bill Wendlingd509a662013-01-29 00:34:06 +0000733 AttributeSet Attrs) const {
734 if (!pImpl) return AttributeSet();
735 if (!Attrs.pImpl) return *this;
736
737#ifndef NDEBUG
738 // FIXME it is not obvious how this should work for alignment.
739 // For now, say we can't pass in alignment, which no current use does.
Bill Wendling211316c2013-04-18 20:17:28 +0000740 assert(!Attrs.hasAttribute(Index, Attribute::Alignment) &&
Bill Wendlingd509a662013-01-29 00:34:06 +0000741 "Attempt to change alignment!");
742#endif
743
744 // Add the attribute slots before the one we're trying to add.
745 SmallVector<AttributeSet, 4> AttrSet;
746 uint64_t NumAttrs = pImpl->getNumAttributes();
747 AttributeSet AS;
748 uint64_t LastIndex = 0;
749 for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
Bill Wendling211316c2013-04-18 20:17:28 +0000750 if (getSlotIndex(I) >= Index) {
751 if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
Bill Wendlingd509a662013-01-29 00:34:06 +0000752 break;
753 }
754 LastIndex = I + 1;
755 AttrSet.push_back(getSlotAttributes(I));
756 }
757
Bill Wendlingd2196752013-01-30 23:07:40 +0000758 // Now remove the attribute from the correct slot. There may already be an
Bill Wendlingd509a662013-01-29 00:34:06 +0000759 // AttributeSet there.
Bill Wendling211316c2013-04-18 20:17:28 +0000760 AttrBuilder B(AS, Index);
Bill Wendlingd509a662013-01-29 00:34:06 +0000761
762 for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
Bill Wendling211316c2013-04-18 20:17:28 +0000763 if (Attrs.getSlotIndex(I) == Index) {
764 B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Index);
Bill Wendlingd509a662013-01-29 00:34:06 +0000765 break;
766 }
767
Bill Wendling211316c2013-04-18 20:17:28 +0000768 AttrSet.push_back(AttributeSet::get(C, Index, B));
Bill Wendlingd509a662013-01-29 00:34:06 +0000769
770 // Add the remaining attribute slots.
771 for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
772 AttrSet.push_back(getSlotAttributes(I));
773
774 return get(C, AttrSet);
775}
776
777//===----------------------------------------------------------------------===//
778// AttributeSet Accessor Methods
779//===----------------------------------------------------------------------===//
780
Bill Wendling5d020a32013-02-10 05:00:40 +0000781LLVMContext &AttributeSet::getContext() const {
782 return pImpl->getContext();
783}
784
Bill Wendling211316c2013-04-18 20:17:28 +0000785AttributeSet AttributeSet::getParamAttributes(unsigned Index) const {
786 return pImpl && hasAttributes(Index) ?
Bill Wendlingd509a662013-01-29 00:34:06 +0000787 AttributeSet::get(pImpl->getContext(),
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000788 ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
Bill Wendling211316c2013-04-18 20:17:28 +0000789 std::make_pair(Index, getAttributes(Index)))) :
Bill Wendlingd509a662013-01-29 00:34:06 +0000790 AttributeSet();
791}
792
793AttributeSet AttributeSet::getRetAttributes() const {
794 return pImpl && hasAttributes(ReturnIndex) ?
795 AttributeSet::get(pImpl->getContext(),
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000796 ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
Bill Wendlingd509a662013-01-29 00:34:06 +0000797 std::make_pair(ReturnIndex,
798 getAttributes(ReturnIndex)))) :
799 AttributeSet();
800}
801
802AttributeSet AttributeSet::getFnAttributes() const {
803 return pImpl && hasAttributes(FunctionIndex) ?
804 AttributeSet::get(pImpl->getContext(),
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000805 ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
Bill Wendlingd509a662013-01-29 00:34:06 +0000806 std::make_pair(FunctionIndex,
807 getAttributes(FunctionIndex)))) :
808 AttributeSet();
809}
810
811bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000812 AttributeSetNode *ASN = getAttributes(Index);
813 return ASN ? ASN->hasAttribute(Kind) : false;
Bill Wendlingd509a662013-01-29 00:34:06 +0000814}
815
Bill Wendlingbce7b972013-02-13 08:42:21 +0000816bool AttributeSet::hasAttribute(unsigned Index, StringRef Kind) const {
817 AttributeSetNode *ASN = getAttributes(Index);
818 return ASN ? ASN->hasAttribute(Kind) : false;
819}
820
Bill Wendlingd509a662013-01-29 00:34:06 +0000821bool AttributeSet::hasAttributes(unsigned Index) const {
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000822 AttributeSetNode *ASN = getAttributes(Index);
823 return ASN ? ASN->hasAttributes() : false;
Bill Wendlingd509a662013-01-29 00:34:06 +0000824}
825
826/// \brief Return true if the specified attribute is set for at least one
827/// parameter or for the return value.
828bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const {
829 if (pImpl == 0) return false;
830
831 for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I)
Benjamin Kramer741146b2013-07-11 12:13:16 +0000832 for (AttributeSetImpl::iterator II = pImpl->begin(I),
Bill Wendlingd509a662013-01-29 00:34:06 +0000833 IE = pImpl->end(I); II != IE; ++II)
NAKAMURA Takumib0944392013-01-31 03:47:28 +0000834 if (II->hasAttribute(Attr))
Bill Wendlingd509a662013-01-29 00:34:06 +0000835 return true;
836
837 return false;
838}
839
Bill Wendlingbce7b972013-02-13 08:42:21 +0000840Attribute AttributeSet::getAttribute(unsigned Index,
841 Attribute::AttrKind Kind) const {
842 AttributeSetNode *ASN = getAttributes(Index);
843 return ASN ? ASN->getAttribute(Kind) : Attribute();
844}
845
846Attribute AttributeSet::getAttribute(unsigned Index,
847 StringRef Kind) const {
848 AttributeSetNode *ASN = getAttributes(Index);
849 return ASN ? ASN->getAttribute(Kind) : Attribute();
850}
851
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000852unsigned AttributeSet::getParamAlignment(unsigned Index) const {
853 AttributeSetNode *ASN = getAttributes(Index);
854 return ASN ? ASN->getAlignment() : 0;
Bill Wendlingd509a662013-01-29 00:34:06 +0000855}
856
857unsigned AttributeSet::getStackAlignment(unsigned Index) const {
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000858 AttributeSetNode *ASN = getAttributes(Index);
859 return ASN ? ASN->getStackAlignment() : 0;
Bill Wendlingd509a662013-01-29 00:34:06 +0000860}
861
Rafael Espindolacbf5a7a2013-05-01 13:07:03 +0000862std::string AttributeSet::getAsString(unsigned Index,
Bill Wendling829b4782013-02-11 08:43:33 +0000863 bool InAttrGrp) const {
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000864 AttributeSetNode *ASN = getAttributes(Index);
Rafael Espindolacbf5a7a2013-05-01 13:07:03 +0000865 return ASN ? ASN->getAsString(InAttrGrp) : std::string("");
Bill Wendlingd509a662013-01-29 00:34:06 +0000866}
867
868/// \brief The attributes for the specified index are returned.
Bill Wendling211316c2013-04-18 20:17:28 +0000869AttributeSetNode *AttributeSet::getAttributes(unsigned Index) const {
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000870 if (!pImpl) return 0;
Bill Wendlingd509a662013-01-29 00:34:06 +0000871
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000872 // Loop through to find the attribute node we want.
873 for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I)
Bill Wendling211316c2013-04-18 20:17:28 +0000874 if (pImpl->getSlotIndex(I) == Index)
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000875 return pImpl->getSlotNode(I);
Bill Wendlingd509a662013-01-29 00:34:06 +0000876
Bill Wendlingf2955aa2013-01-29 03:20:31 +0000877 return 0;
Bill Wendlingd509a662013-01-29 00:34:06 +0000878}
879
Bill Wendling211316c2013-04-18 20:17:28 +0000880AttributeSet::iterator AttributeSet::begin(unsigned Slot) const {
Bill Wendlinga9174862013-01-31 23:53:05 +0000881 if (!pImpl)
882 return ArrayRef<Attribute>().begin();
Bill Wendling211316c2013-04-18 20:17:28 +0000883 return pImpl->begin(Slot);
Bill Wendlinga9174862013-01-31 23:53:05 +0000884}
885
Bill Wendling211316c2013-04-18 20:17:28 +0000886AttributeSet::iterator AttributeSet::end(unsigned Slot) const {
Bill Wendlinga9174862013-01-31 23:53:05 +0000887 if (!pImpl)
888 return ArrayRef<Attribute>().end();
Bill Wendling211316c2013-04-18 20:17:28 +0000889 return pImpl->end(Slot);
Bill Wendlinga9174862013-01-31 23:53:05 +0000890}
891
Bill Wendlingd509a662013-01-29 00:34:06 +0000892//===----------------------------------------------------------------------===//
893// AttributeSet Introspection Methods
894//===----------------------------------------------------------------------===//
895
896/// \brief Return the number of slots used in this attribute list. This is the
897/// number of arguments that have an attribute set on them (including the
898/// function itself).
899unsigned AttributeSet::getNumSlots() const {
900 return pImpl ? pImpl->getNumAttributes() : 0;
901}
902
Rafael Espindoladd275302013-04-30 16:53:38 +0000903unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
Bill Wendlingd509a662013-01-29 00:34:06 +0000904 assert(pImpl && Slot < pImpl->getNumAttributes() &&
905 "Slot # out of range!");
906 return pImpl->getSlotIndex(Slot);
907}
908
909AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const {
910 assert(pImpl && Slot < pImpl->getNumAttributes() &&
911 "Slot # out of range!");
912 return pImpl->getSlotAttributes(Slot);
913}
914
915uint64_t AttributeSet::Raw(unsigned Index) const {
916 // FIXME: Remove this.
917 return pImpl ? pImpl->Raw(Index) : 0;
918}
919
920void AttributeSet::dump() const {
921 dbgs() << "PAL[\n";
922
923 for (unsigned i = 0, e = getNumSlots(); i < e; ++i) {
924 uint64_t Index = getSlotIndex(i);
925 dbgs() << " { ";
926 if (Index == ~0U)
927 dbgs() << "~0U";
928 else
929 dbgs() << Index;
930 dbgs() << " => " << getAsString(Index) << " }\n";
931 }
932
933 dbgs() << "]\n";
934}
935
Bill Wendlingabf3feb2012-10-05 06:44:41 +0000936//===----------------------------------------------------------------------===//
Bill Wendlingcd330342013-01-04 23:27:34 +0000937// AttrBuilder Method Implementations
Bill Wendlingabf3feb2012-10-05 06:44:41 +0000938//===----------------------------------------------------------------------===//
939
Bill Wendling211316c2013-04-18 20:17:28 +0000940AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index)
Benjamin Kramer45e7d532013-02-16 19:13:18 +0000941 : Attrs(0), Alignment(0), StackAlignment(0) {
Bill Wendling56b0b2a2013-01-27 21:23:46 +0000942 AttributeSetImpl *pImpl = AS.pImpl;
Bill Wendling096f5442013-01-07 08:24:35 +0000943 if (!pImpl) return;
944
Bill Wendling9eb689c2013-01-28 00:21:34 +0000945 for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) {
Bill Wendling211316c2013-04-18 20:17:28 +0000946 if (pImpl->getSlotIndex(I) != Index) continue;
Bill Wendling096f5442013-01-07 08:24:35 +0000947
Benjamin Kramer741146b2013-07-11 12:13:16 +0000948 for (AttributeSetImpl::iterator II = pImpl->begin(I),
Bill Wendling9eb689c2013-01-28 00:21:34 +0000949 IE = pImpl->end(I); II != IE; ++II)
Bill Wendling23804da2013-01-31 23:38:01 +0000950 addAttribute(*II);
Bill Wendling9eb689c2013-01-28 00:21:34 +0000951
952 break;
953 }
Bill Wendling096f5442013-01-07 08:24:35 +0000954}
955
Bill Wendlingcd330342013-01-04 23:27:34 +0000956void AttrBuilder::clear() {
Benjamin Kramereaf706b2013-02-18 12:09:51 +0000957 Attrs.reset();
Bill Wendlingcd330342013-01-04 23:27:34 +0000958 Alignment = StackAlignment = 0;
959}
960
961AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) {
Benjamin Kramereaf706b2013-02-18 12:09:51 +0000962 assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
Bill Wendling1c7cc8a2013-01-31 23:16:25 +0000963 assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
964 "Adding alignment attribute without adding alignment value!");
Benjamin Kramereaf706b2013-02-18 12:09:51 +0000965 Attrs[Val] = true;
Bill Wendling7c04e042012-10-09 19:01:18 +0000966 return *this;
Bill Wendlingabf3feb2012-10-05 06:44:41 +0000967}
968
Bill Wendling23804da2013-01-31 23:38:01 +0000969AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) {
Bill Wendling0a437302013-02-10 10:13:23 +0000970 if (Attr.isStringAttribute()) {
971 addAttribute(Attr.getKindAsString(), Attr.getValueAsString());
972 return *this;
973 }
974
Bill Wendling3f12ac22013-02-05 22:37:24 +0000975 Attribute::AttrKind Kind = Attr.getKindAsEnum();
Benjamin Kramereaf706b2013-02-18 12:09:51 +0000976 Attrs[Kind] = true;
Bill Wendling1aa9d9e2013-01-28 05:23:28 +0000977
Bill Wendling3f12ac22013-02-05 22:37:24 +0000978 if (Kind == Attribute::Alignment)
Bill Wendling1aa9d9e2013-01-28 05:23:28 +0000979 Alignment = Attr.getAlignment();
Bill Wendling3f12ac22013-02-05 22:37:24 +0000980 else if (Kind == Attribute::StackAlignment)
Bill Wendling1aa9d9e2013-01-28 05:23:28 +0000981 StackAlignment = Attr.getStackAlignment();
982 return *this;
983}
984
Bill Wendlingb9c5b1a2013-02-05 08:09:32 +0000985AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) {
986 TargetDepAttrs[A] = V;
987 return *this;
988}
989
Bill Wendling23804da2013-01-31 23:38:01 +0000990AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) {
Benjamin Kramereaf706b2013-02-18 12:09:51 +0000991 assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
992 Attrs[Val] = false;
Bill Wendling23804da2013-01-31 23:38:01 +0000993
994 if (Val == Attribute::Alignment)
995 Alignment = 0;
996 else if (Val == Attribute::StackAlignment)
997 StackAlignment = 0;
998
999 return *this;
1000}
1001
Bill Wendlingd2196752013-01-30 23:07:40 +00001002AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) {
Bill Wendling211316c2013-04-18 20:17:28 +00001003 unsigned Slot = ~0U;
Bill Wendlingf1c94e32013-02-01 00:13:50 +00001004 for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
1005 if (A.getSlotIndex(I) == Index) {
Bill Wendling211316c2013-04-18 20:17:28 +00001006 Slot = I;
Bill Wendlingf1c94e32013-02-01 00:13:50 +00001007 break;
Bill Wendling1aa9d9e2013-01-28 05:23:28 +00001008 }
Bill Wendlingf1c94e32013-02-01 00:13:50 +00001009
Bill Wendling211316c2013-04-18 20:17:28 +00001010 assert(Slot != ~0U && "Couldn't find index in AttributeSet!");
Bill Wendlingf1c94e32013-02-01 00:13:50 +00001011
Bill Wendling211316c2013-04-18 20:17:28 +00001012 for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) {
Bill Wendling7cde51d2013-02-12 07:56:49 +00001013 Attribute Attr = *I;
1014 if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
1015 Attribute::AttrKind Kind = I->getKindAsEnum();
Benjamin Kramereaf706b2013-02-18 12:09:51 +00001016 Attrs[Kind] = false;
Bill Wendlingf1c94e32013-02-01 00:13:50 +00001017
Bill Wendling7cde51d2013-02-12 07:56:49 +00001018 if (Kind == Attribute::Alignment)
1019 Alignment = 0;
1020 else if (Kind == Attribute::StackAlignment)
1021 StackAlignment = 0;
1022 } else {
1023 assert(Attr.isStringAttribute() && "Invalid attribute type!");
1024 std::map<std::string, std::string>::iterator
1025 Iter = TargetDepAttrs.find(Attr.getKindAsString());
1026 if (Iter != TargetDepAttrs.end())
1027 TargetDepAttrs.erase(Iter);
1028 }
Bill Wendling1aa9d9e2013-01-28 05:23:28 +00001029 }
1030
1031 return *this;
1032}
1033
Bill Wendlingb9c5b1a2013-02-05 08:09:32 +00001034AttrBuilder &AttrBuilder::removeAttribute(StringRef A) {
1035 std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A);
1036 if (I != TargetDepAttrs.end())
1037 TargetDepAttrs.erase(I);
1038 return *this;
1039}
1040
Bill Wendling50d27842012-10-15 20:35:56 +00001041AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) {
Bill Wendlingabd5ba22012-10-14 03:58:29 +00001042 if (Align == 0) return *this;
Bill Wendlingcd330342013-01-04 23:27:34 +00001043
Bill Wendlingabf3feb2012-10-05 06:44:41 +00001044 assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1045 assert(Align <= 0x40000000 && "Alignment too large.");
Bill Wendlingcd330342013-01-04 23:27:34 +00001046
Benjamin Kramereaf706b2013-02-18 12:09:51 +00001047 Attrs[Attribute::Alignment] = true;
Bill Wendlingcd330342013-01-04 23:27:34 +00001048 Alignment = Align;
Bill Wendlingabd5ba22012-10-14 03:58:29 +00001049 return *this;
Chris Lattner3e13b8c2008-01-02 23:42:30 +00001050}
1051
Bill Wendlingcd330342013-01-04 23:27:34 +00001052AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) {
1053 // Default alignment, allow the target to define how to align it.
1054 if (Align == 0) return *this;
1055
1056 assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
1057 assert(Align <= 0x100 && "Alignment too large.");
1058
Benjamin Kramereaf706b2013-02-18 12:09:51 +00001059 Attrs[Attribute::StackAlignment] = true;
Bill Wendlingcd330342013-01-04 23:27:34 +00001060 StackAlignment = Align;
1061 return *this;
1062}
1063
Bill Wendlinge2614922013-02-06 01:16:00 +00001064AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) {
1065 // FIXME: What if both have alignments, but they don't match?!
1066 if (!Alignment)
1067 Alignment = B.Alignment;
1068
1069 if (!StackAlignment)
1070 StackAlignment = B.StackAlignment;
1071
Benjamin Kramer45e7d532013-02-16 19:13:18 +00001072 Attrs |= B.Attrs;
Bill Wendlinge2614922013-02-06 01:16:00 +00001073
1074 for (td_const_iterator I = B.TargetDepAttrs.begin(),
1075 E = B.TargetDepAttrs.end(); I != E; ++I)
1076 TargetDepAttrs[I->first] = I->second;
1077
1078 return *this;
1079}
1080
Bill Wendling4b001442013-02-06 01:33:42 +00001081bool AttrBuilder::contains(StringRef A) const {
1082 return TargetDepAttrs.find(A) != TargetDepAttrs.end();
1083}
1084
Bill Wendling50d27842012-10-15 20:35:56 +00001085bool AttrBuilder::hasAttributes() const {
Benjamin Kramereaf706b2013-02-18 12:09:51 +00001086 return !Attrs.none() || !TargetDepAttrs.empty();
Bill Wendlingc6daefa2012-10-08 23:27:46 +00001087}
Bill Wendling9ac69f92013-01-04 20:54:35 +00001088
Bill Wendlingd2196752013-01-30 23:07:40 +00001089bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
Bill Wendling211316c2013-04-18 20:17:28 +00001090 unsigned Slot = ~0U;
Bill Wendling9ca01da2013-02-02 00:42:06 +00001091 for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
1092 if (A.getSlotIndex(I) == Index) {
Bill Wendling211316c2013-04-18 20:17:28 +00001093 Slot = I;
Bill Wendling9ca01da2013-02-02 00:42:06 +00001094 break;
1095 }
1096
Bill Wendling211316c2013-04-18 20:17:28 +00001097 assert(Slot != ~0U && "Couldn't find the index!");
Bill Wendling9ca01da2013-02-02 00:42:06 +00001098
Bill Wendling211316c2013-04-18 20:17:28 +00001099 for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot);
Bill Wendling7cde51d2013-02-12 07:56:49 +00001100 I != E; ++I) {
1101 Attribute Attr = *I;
1102 if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
Benjamin Kramereaf706b2013-02-18 12:09:51 +00001103 if (Attrs[I->getKindAsEnum()])
Bill Wendling7cde51d2013-02-12 07:56:49 +00001104 return true;
1105 } else {
1106 assert(Attr.isStringAttribute() && "Invalid attribute kind!");
1107 return TargetDepAttrs.find(Attr.getKindAsString())!=TargetDepAttrs.end();
1108 }
1109 }
Bill Wendling9ca01da2013-02-02 00:42:06 +00001110
1111 return false;
Bill Wendling70f39172012-10-09 00:01:21 +00001112}
Bill Wendling9ac69f92013-01-04 20:54:35 +00001113
Bill Wendling50d27842012-10-15 20:35:56 +00001114bool AttrBuilder::hasAlignmentAttr() const {
Bill Wendlingcd330342013-01-04 23:27:34 +00001115 return Alignment != 0;
Bill Wendlingc6daefa2012-10-08 23:27:46 +00001116}
1117
Bill Wendlingd509a662013-01-29 00:34:06 +00001118bool AttrBuilder::operator==(const AttrBuilder &B) {
Benjamin Kramer45e7d532013-02-16 19:13:18 +00001119 if (Attrs != B.Attrs)
1120 return false;
Bill Wendling4b001442013-02-06 01:33:42 +00001121
1122 for (td_const_iterator I = TargetDepAttrs.begin(),
1123 E = TargetDepAttrs.end(); I != E; ++I)
1124 if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end())
1125 return false;
1126
1127 return Alignment == B.Alignment && StackAlignment == B.StackAlignment;
Bill Wendlingd509a662013-01-29 00:34:06 +00001128}
1129
1130AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
Bill Wendling56aeccc2013-02-04 23:32:23 +00001131 // FIXME: Remove this in 4.0.
Bill Wendling60011b82013-01-29 01:43:29 +00001132 if (!Val) return *this;
1133
Bill Wendlingd509a662013-01-29 00:34:06 +00001134 for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
1135 I = Attribute::AttrKind(I + 1)) {
1136 if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) {
Benjamin Kramereaf706b2013-02-18 12:09:51 +00001137 Attrs[I] = true;
Bill Wendlingd509a662013-01-29 00:34:06 +00001138
1139 if (I == Attribute::Alignment)
1140 Alignment = 1ULL << ((A >> 16) - 1);
1141 else if (I == Attribute::StackAlignment)
1142 StackAlignment = 1ULL << ((A >> 26)-1);
1143 }
1144 }
1145
1146 return *this;
1147}
1148
Bill Wendling57625a42013-01-25 23:09:36 +00001149//===----------------------------------------------------------------------===//
1150// AttributeFuncs Function Defintions
1151//===----------------------------------------------------------------------===//
1152
Bill Wendlingc79cdff2013-02-01 01:04:27 +00001153/// \brief Which attributes cannot be applied to a type.
Bill Wendlingd2196752013-01-30 23:07:40 +00001154AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) {
Bill Wendling57625a42013-01-25 23:09:36 +00001155 AttrBuilder Incompatible;
1156
1157 if (!Ty->isIntegerTy())
1158 // Attribute that only apply to integers.
1159 Incompatible.addAttribute(Attribute::SExt)
1160 .addAttribute(Attribute::ZExt);
1161
1162 if (!Ty->isPointerTy())
1163 // Attribute that only apply to pointers.
1164 Incompatible.addAttribute(Attribute::ByVal)
1165 .addAttribute(Attribute::Nest)
1166 .addAttribute(Attribute::NoAlias)
1167 .addAttribute(Attribute::NoCapture)
Nick Lewyckyc2ec0722013-07-06 00:29:58 +00001168 .addAttribute(Attribute::ReadNone)
1169 .addAttribute(Attribute::ReadOnly)
Bill Wendling57625a42013-01-25 23:09:36 +00001170 .addAttribute(Attribute::StructRet);
1171
Bill Wendlingd2196752013-01-30 23:07:40 +00001172 return AttributeSet::get(Ty->getContext(), Index, Incompatible);
Bill Wendling57625a42013-01-25 23:09:36 +00001173}