llvm.org GIT mirror llvm / cb3de0b
Attributes Rewrite Convert the internal representation of the Attributes class into a pointer to an opaque object that's uniqued by and stored in the LLVMContext object. The Attributes class then becomes a thin wrapper around this opaque object. Eventually, the internal representation will be expanded to include attributes that represent code generation options, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165917 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 8 years ago
21 changed file(s) with 166 addition(s) and 126 deletion(s). Raw diff Collapse all Expand all
8888 ZExt = 27 ///< Zero extended before/after call
8989 };
9090 private:
91 AttributesImpl Attrs;
91 AttributesImpl *Attrs;
9292
9393 explicit Attributes(AttributesImpl *A);
9494 public:
9595 Attributes() : Attrs(0) {}
96 explicit Attributes(uint64_t Val);
97 explicit Attributes(LLVMContext &C, AttrVal Val);
96 explicit Attributes(LLVMContext &C, ArrayRef Vals);
9897 Attributes(const Attributes &A);
9998
10099 class Builder {
104103 Builder() : Bits(0) {}
105104 explicit Builder(uint64_t B) : Bits(B) {}
106105 Builder(const Attributes &A) : Bits(A.Raw()) {}
106 Builder(const Builder &B) : Bits(B.Bits) {}
107107
108108 void clear() { Bits = 0; }
109109
165165
166166 /// get - Return a uniquified Attributes object. This takes the uniquified
167167 /// value from the Builder and wraps it in the Attributes class.
168 static Attributes get(Builder &B);
169168 static Attributes get(LLVMContext &Context, Builder &B);
170169
171170 /// @brief Return true if the attribute is present.
173172
174173 /// @brief Return true if attributes exist
175174 bool hasAttributes() const {
176 return Attrs.hasAttributes();
175 return Attrs && Attrs->hasAttributes();
177176 }
178177
179178 /// @brief Return true if the attributes are a non-null intersection.
224223 }
225224
226225 bool operator == (const Attributes &A) const {
227 return Attrs.Bits == A.Attrs.Bits;
226 return Attrs == A.Attrs;
228227 }
229228 bool operator != (const Attributes &A) const {
230 return Attrs.Bits != A.Attrs.Bits;
229 return Attrs != A.Attrs;
231230 }
232231
233232 uint64_t Raw() const;
260259 /// containing the LLVM attributes that have been decoded from the given
261260 /// integer. This function must stay in sync with
262261 /// 'encodeLLVMAttributesForBitcode'.
263 static Attributes decodeLLVMAttributesForBitcode(uint64_t EncodedAttrs) {
262 static Attributes decodeLLVMAttributesForBitcode(LLVMContext &C,
263 uint64_t EncodedAttrs) {
264264 // The alignment is stored as a 16-bit raw value from bits 31--16. We shift
265265 // the bits above 31 down by 11 bits.
266266 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
271271 if (Alignment)
272272 B.addAlignmentAttr(Alignment);
273273 B.addRawValue((EncodedAttrs & (0xfffULL << 32)) >> 11);
274 return Attributes::get(B);
274 return Attributes::get(C, B);
275275 }
276276
277277 /// getAsString - The set of Attributes set in Attributes is converted to a
293293 ///< Index 0 is used for return value attributes.
294294 ///< Index ~0U is used for function attributes.
295295
296 static AttributeWithIndex get(unsigned Idx,
296 static AttributeWithIndex get(LLVMContext &C, unsigned Idx,
297297 ArrayRef Attrs) {
298298 Attributes::Builder B;
299299
303303
304304 AttributeWithIndex P;
305305 P.Index = Idx;
306 P.Attrs = Attributes::get(B);
306 P.Attrs = Attributes::get(C, B);
307307 return P;
308308 }
309309 static AttributeWithIndex get(unsigned Idx, Attributes Attrs) {
179179 // Function Attributes are stored at ~0 index
180180 Attributes::Builder B;
181181 B.addAttribute(N);
182 addAttribute(~0U, Attributes::get(B));
182 addAttribute(~0U, Attributes::get(getContext(), B));
183183 }
184184
185185 /// removeFnAttr - Remove function attributes from this function.
279279 void setDoesNotAlias(unsigned n) {
280280 Attributes::Builder B;
281281 B.addAttribute(Attributes::NoAlias);
282 addAttribute(n, Attributes::get(B));
282 addAttribute(n, Attributes::get(getContext(), B));
283283 }
284284
285285 /// @brief Determine if the parameter can be captured.
290290 void setDoesNotCapture(unsigned n) {
291291 Attributes::Builder B;
292292 B.addAttribute(Attributes::NoCapture);
293 addAttribute(n, Attributes::get(B));
293 addAttribute(n, Attributes::get(getContext(), B));
294294 }
295295
296296 /// copyAttributesFrom - copy all additional attributes (those not needed to
12731273 void setIsNoInline() {
12741274 Attributes::Builder B;
12751275 B.addAttribute(Attributes::NoInline);
1276 addAttribute(~0, Attributes::get(B));
1276 addAttribute(~0, Attributes::get(getContext(), B));
12771277 }
12781278
12791279 /// @brief Return true if the call can return twice
12831283 void setCanReturnTwice() {
12841284 Attributes::Builder B;
12851285 B.addAttribute(Attributes::ReturnsTwice);
1286 addAttribute(~0U, Attributes::get(B));
1286 addAttribute(~0U, Attributes::get(getContext(), B));
12871287 }
12881288
12891289 /// @brief Determine if the call does not access memory.
12931293 void setDoesNotAccessMemory() {
12941294 Attributes::Builder B;
12951295 B.addAttribute(Attributes::ReadNone);
1296 addAttribute(~0U, Attributes::get(B));
1296 addAttribute(~0U, Attributes::get(getContext(), B));
12971297 }
12981298
12991299 /// @brief Determine if the call does not access or only reads memory.
13031303 void setOnlyReadsMemory() {
13041304 Attributes::Builder B;
13051305 B.addAttribute(Attributes::ReadOnly);
1306 addAttribute(~0, Attributes::get(B));
1306 addAttribute(~0, Attributes::get(getContext(), B));
13071307 }
13081308
13091309 /// @brief Determine if the call cannot return.
13111311 void setDoesNotReturn() {
13121312 Attributes::Builder B;
13131313 B.addAttribute(Attributes::NoReturn);
1314 addAttribute(~0, Attributes::get(B));
1314 addAttribute(~0, Attributes::get(getContext(), B));
13151315 }
13161316
13171317 /// @brief Determine if the call cannot unwind.
13191319 void setDoesNotThrow() {
13201320 Attributes::Builder B;
13211321 B.addAttribute(Attributes::NoUnwind);
1322 addAttribute(~0, Attributes::get(B));
1322 addAttribute(~0, Attributes::get(getContext(), B));
13231323 }
13241324
13251325 /// @brief Determine if the call returns a structure through first
30283028 void setIsNoInline() {
30293029 Attributes::Builder B;
30303030 B.addAttribute(Attributes::NoInline);
3031 addAttribute(~0, Attributes::get(B));
3031 addAttribute(~0, Attributes::get(getContext(), B));
30323032 }
30333033
30343034 /// @brief Determine if the call does not access memory.
30383038 void setDoesNotAccessMemory() {
30393039 Attributes::Builder B;
30403040 B.addAttribute(Attributes::ReadNone);
3041 addAttribute(~0, Attributes::get(B));
3041 addAttribute(~0, Attributes::get(getContext(), B));
30423042 }
30433043
30443044 /// @brief Determine if the call does not access or only reads memory.
30483048 void setOnlyReadsMemory() {
30493049 Attributes::Builder B;
30503050 B.addAttribute(Attributes::ReadOnly);
3051 addAttribute(~0, Attributes::get(B));
3051 addAttribute(~0, Attributes::get(getContext(), B));
30523052 }
30533053
30543054 /// @brief Determine if the call cannot return.
30563056 void setDoesNotReturn() {
30573057 Attributes::Builder B;
30583058 B.addAttribute(Attributes::NoReturn);
3059 addAttribute(~0, Attributes::get(B));
3059 addAttribute(~0, Attributes::get(getContext(), B));
30603060 }
30613061
30623062 /// @brief Determine if the call cannot unwind.
30643064 void setDoesNotThrow() {
30653065 Attributes::Builder B;
30663066 B.addAttribute(Attributes::NoUnwind);
3067 addAttribute(~0, Attributes::get(B));
3067 addAttribute(~0, Attributes::get(getContext(), B));
30683068 }
30693069
30703070 /// @brief Determine if the call returns a structure through first
4949 /// Intrinsic::getType(ID) - Return the function type for an intrinsic.
5050 ///
5151 FunctionType *getType(LLVMContext &Context, ID id,
52 ArrayRef Tys = ArrayRef());
52 ArrayRef Tys = ArrayRef());
5353
5454 /// Intrinsic::isOverloaded(ID) - Returns true if the intrinsic can be
5555 /// overloaded.
5757
5858 /// Intrinsic::getAttributes(ID) - Return the attributes for an intrinsic.
5959 ///
60 AttrListPtr getAttributes(ID id);
60 AttrListPtr getAttributes(LLVMContext &C, ID id);
6161
6262 /// Intrinsic::getDeclaration(M, ID) - Create or insert an LLVM Function
6363 /// declaration for an intrinsic, and return it.
14421442 // Otherwise, handle normal operands.
14431443 if (ParseOptionalAttrs(ArgAttrs, 0) || ParseValue(ArgTy, V, PFS))
14441444 return true;
1445 ArgList.push_back(ParamInfo(ArgLoc, V, Attributes::get(ArgAttrs)));
1445 ArgList.push_back(ParamInfo(ArgLoc, V, Attributes::get(V->getContext(),
1446 ArgAttrs)));
14461447 }
14471448
14481449 Lex.Lex(); // Lex the ')'.
14911492 if (!FunctionType::isValidArgumentType(ArgTy))
14921493 return Error(TypeLoc, "invalid type for function argument");
14931494
1494 ArgList.push_back(ArgInfo(TypeLoc, ArgTy, Attributes::get(Attrs), Name));
1495 ArgList.push_back(ArgInfo(TypeLoc, ArgTy,
1496 Attributes::get(ArgTy->getContext(),
1497 Attrs), Name));
14951498
14961499 while (EatIfPresent(lltok::comma)) {
14971500 // Handle ... at end of arg list.
15171520 if (!ArgTy->isFirstClassType())
15181521 return Error(TypeLoc, "invalid type for function argument");
15191522
1520 ArgList.push_back(ArgInfo(TypeLoc, ArgTy, Attributes::get(Attrs), Name));
1523 ArgList.push_back(ArgInfo(TypeLoc, ArgTy,
1524 Attributes::get(ArgTy->getContext(), Attrs),
1525 Name));
15211526 }
15221527 }
15231528
27652770 SmallVector Attrs;
27662771
27672772 if (RetAttrs.hasAttributes())
2768 Attrs.push_back(AttributeWithIndex::get(0, Attributes::get(RetAttrs)));
2773 Attrs.push_back(AttributeWithIndex::get(0,
2774 Attributes::get(RetType->getContext(),
2775 RetAttrs)));
27692776
27702777 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
27712778 ParamTypeList.push_back(ArgList[i].Ty);
27742781 }
27752782
27762783 if (FuncAttrs.hasAttributes())
2777 Attrs.push_back(AttributeWithIndex::get(~0, Attributes::get(FuncAttrs)));
2784 Attrs.push_back(AttributeWithIndex::get(~0,
2785 Attributes::get(RetType->getContext(),
2786 FuncAttrs)));
27782787
27792788 AttrListPtr PAL = AttrListPtr::get(Attrs);
27802789
32963305 // Set up the Attributes for the function.
32973306 SmallVector Attrs;
32983307 if (RetAttrs.hasAttributes())
3299 Attrs.push_back(AttributeWithIndex::get(0, Attributes::get(RetAttrs)));
3308 Attrs.push_back(AttributeWithIndex::get(0,
3309 Attributes::get(Callee->getContext(),
3310 RetAttrs)));
33003311
33013312 SmallVector Args;
33023313
33243335 return Error(CallLoc, "not enough parameters specified for call");
33253336
33263337 if (FnAttrs.hasAttributes())
3327 Attrs.push_back(AttributeWithIndex::get(~0, Attributes::get(FnAttrs)));
3338 Attrs.push_back(AttributeWithIndex::get(~0,
3339 Attributes::get(Callee->getContext(),
3340 FnAttrs)));
33283341
33293342 // Finish off the Attributes and check them
33303343 AttrListPtr PAL = AttrListPtr::get(Attrs);
36923705 // Set up the Attributes for the function.
36933706 SmallVector Attrs;
36943707 if (RetAttrs.hasAttributes())
3695 Attrs.push_back(AttributeWithIndex::get(0, Attributes::get(RetAttrs)));
3708 Attrs.push_back(AttributeWithIndex::get(0,
3709 Attributes::get(Callee->getContext(),
3710 RetAttrs)));
36963711
36973712 SmallVector Args;
36983713
37203735 return Error(CallLoc, "not enough parameters specified for call");
37213736
37223737 if (FnAttrs.hasAttributes())
3723 Attrs.push_back(AttributeWithIndex::get(~0, Attributes::get(FnAttrs)));
3738 Attrs.push_back(AttributeWithIndex::get(~0,
3739 Attributes::get(Callee->getContext(),
3740 FnAttrs)));
37243741
37253742 // Finish off the Attributes and check them
37263743 AttrListPtr PAL = AttrListPtr::get(Attrs);
475475
476476 for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
477477 Attributes ReconstitutedAttr =
478 Attributes::decodeLLVMAttributesForBitcode(Record[i+1]);
478 Attributes::decodeLLVMAttributesForBitcode(Context, Record[i+1]);
479479 Record[i+1] = ReconstitutedAttr.Raw();
480480 }
481481
482482 for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
483 if (Attributes(Record[i+1]).hasAttributes())
483 Attributes::Builder B(Record[i+1]);
484 if (B.hasAttributes())
484485 Attrs.push_back(AttributeWithIndex::get(Record[i],
485 Attributes(Record[i+1])));
486 Attributes::get(Context, B)));
486487 }
487488
488489 MAttributes.push_back(AttrListPtr::get(Attrs));
8282 #undef GET_INTRINSIC_OVERLOAD_TABLE
8383 }
8484
85 /// This defines the "getAttributes(ID id)" method.
85 /// This defines the "getAttributes(LLVMContext &C, ID id)" method.
8686 #define GET_INTRINSIC_ATTRIBUTES
8787 #include "MBlazeGenIntrinsics.inc"
8888 #undef GET_INTRINSIC_ATTRIBUTES
103103 Type **Tys,
104104 unsigned numTy) const {
105105 assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
106 AttrListPtr AList = getAttributes((mblazeIntrinsic::ID) IntrID);
106 AttrListPtr AList = getAttributes(M->getContext(),
107 (mblazeIntrinsic::ID) IntrID);
107108 return cast(M->getOrInsertFunction(getName(IntrID),
108109 getType(M->getContext(), IntrID),
109110 AList));
763763 // required when new return value attributes are added.
764764 if (NRetTy->isVoidTy())
765765 RAttrs =
766 Attributes::get(Attributes::Builder(RAttrs).
766 Attributes::get(NRetTy->getContext(), Attributes::Builder(RAttrs).
767767 removeAttributes(Attributes::typeIncompatible(NRetTy)));
768768 else
769769 assert(!Attributes::Builder(RAttrs).
836836 Attributes FnAttrs = CallPAL.getFnAttributes();
837837 // Adjust in case the function was changed to return void.
838838 RAttrs =
839 Attributes::get(Attributes::Builder(RAttrs).
839 Attributes::get(NF->getContext(), Attributes::Builder(RAttrs).
840840 removeAttributes(Attributes::typeIncompatible(NF->getReturnType())));
841841 if (RAttrs.hasAttributes())
842842 AttributesVec.push_back(AttributeWithIndex::get(0, RAttrs));
214214 Attributes::Builder B;
215215 B.addAttribute(Attributes::ReadOnly)
216216 .addAttribute(Attributes::ReadNone);
217 F->removeAttribute(~0, Attributes::get(B));
217 F->removeAttribute(~0, Attributes::get(F->getContext(), B));
218218
219219 // Add in the new attribute.
220220 B.clear();
221221 B.addAttribute(ReadsMemory ? Attributes::ReadOnly : Attributes::ReadNone);
222 F->addAttribute(~0, Attributes::get(B));
222 F->addAttribute(~0, Attributes::get(F->getContext(), B));
223223
224224 if (ReadsMemory)
225225 ++NumReadOnly;
378378 for (Function::arg_iterator A = F->arg_begin(), E = F->arg_end();
379379 A != E; ++A) {
380380 if (A->getType()->isPointerTy() && !A->hasNoCaptureAttr()) {
381 A->addAttr(Attributes::get(B));
381 A->addAttr(Attributes::get(F->getContext(), B));
382382 ++NumNoCapture;
383383 Changed = true;
384384 }
393393 if (!Tracker.Captured) {
394394 if (Tracker.Uses.empty()) {
395395 // If it's trivially not captured, mark it nocapture now.
396 A->addAttr(Attributes::get(B));
396 A->addAttr(Attributes::get(F->getContext(), B));
397397 ++NumNoCapture;
398398 Changed = true;
399399 } else {
426426 // eg. "void f(int* x) { if (...) f(x); }"
427427 if (ArgumentSCC[0]->Uses.size() == 1 &&
428428 ArgumentSCC[0]->Uses[0] == ArgumentSCC[0]) {
429 ArgumentSCC[0]->Definition->addAttr(Attributes::get(B));
429 ArgumentSCC[0]->
430 Definition->
431 addAttr(Attributes::get(ArgumentSCC[0]->Definition->getContext(), B));
430432 ++NumNoCapture;
431433 Changed = true;
432434 }
468470
469471 for (unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
470472 Argument *A = ArgumentSCC[i]->Definition;
471 A->addAttr(Attributes::get(B));
473 A->addAttr(Attributes::get(A->getContext(), B));
472474 ++NumNoCapture;
473475 Changed = true;
474476 }
20692069 continue;
20702070
20712071 // There can be only one.
2072 return Attrs.removeAttr(C, Attrs.getSlot(i).Index, Attributes::get(B));
2072 return Attrs.removeAttr(C, Attrs.getSlot(i).Index, Attributes::get(C, B));
20732073 }
20742074
20752075 return Attrs;
146146 Function *F = (*I)->getFunction();
147147 const AttrListPtr &PAL = F->getAttributes();
148148 const AttrListPtr &NPAL = PAL.addAttr(F->getContext(), ~0,
149 Attributes::get(NewAttributes));
149 Attributes::get(F->getContext(),
150 NewAttributes));
150151 if (PAL != NPAL) {
151152 MadeChange = true;
152153 F->setAttributes(NPAL);
11161116
11171117 // Add the new return attributes.
11181118 if (RAttrs.hasAttributes())
1119 attrVec.push_back(AttributeWithIndex::get(0, Attributes::get(RAttrs)));
1119 attrVec.push_back(
1120 AttributeWithIndex::get(0, Attributes::get(FT->getContext(), RAttrs)));
11201121
11211122 AI = CS.arg_begin();
11221123 for (unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
17901790 Attributes::Builder B;
17911791 B.addAttribute(Attributes::NoUnwind);
17921792 AttrListPtr Attributes = AttrListPtr().addAttr(M->getContext(), ~0u,
1793 Attributes::get(B));
1793 Attributes::get(M->getContext(), B));
17941794 RetainRVCallee =
17951795 M->getOrInsertFunction("objc_retainAutoreleasedReturnValue", FTy,
17961796 Attributes);
18071807 Attributes::Builder B;
18081808 B.addAttribute(Attributes::NoUnwind);
18091809 AttrListPtr Attributes = AttrListPtr().addAttr(M->getContext(), ~0u,
1810 Attributes::get(B));
1810 Attributes::get(C, B));
18111811 AutoreleaseRVCallee =
18121812 M->getOrInsertFunction("objc_autoreleaseReturnValue", FTy,
18131813 Attributes);
18221822 Attributes::Builder B;
18231823 B.addAttribute(Attributes::NoUnwind);
18241824 AttrListPtr Attributes = AttrListPtr().addAttr(M->getContext(), ~0u,
1825 Attributes::get(B));
1825 Attributes::get(C, B));
18261826 ReleaseCallee =
18271827 M->getOrInsertFunction(
18281828 "objc_release",
18391839 Attributes::Builder B;
18401840 B.addAttribute(Attributes::NoUnwind);
18411841 AttrListPtr Attributes = AttrListPtr().addAttr(M->getContext(), ~0u,
1842 Attributes::get(B));
1842 Attributes::get(C, B));
18431843 RetainCallee =
18441844 M->getOrInsertFunction(
18451845 "objc_retain",
18711871 Attributes::Builder B;
18721872 B.addAttribute(Attributes::NoUnwind);
18731873 AttrListPtr Attributes = AttrListPtr().addAttr(M->getContext(), ~0u,
1874 Attributes::get(B));
1874 Attributes::get(C, B));
18751875 AutoreleaseCallee =
18761876 M->getOrInsertFunction(
18771877 "objc_autorelease",
38493849 Attributes::Builder BNoCapture;
38503850 BNoCapture.addAttribute(Attributes::NoCapture);
38513851 AttrListPtr Attributes = AttrListPtr()
3852 .addAttr(M->getContext(), ~0u, Attributes::get(BNoUnwind))
3853 .addAttr(M->getContext(), 1, Attributes::get(BNoCapture));
3852 .addAttr(M->getContext(), ~0u, Attributes::get(C, BNoUnwind))
3853 .addAttr(M->getContext(), 1, Attributes::get(C, BNoCapture));
38543854
38553855 StoreStrongCallee =
38563856 M->getOrInsertFunction(
38703870 Attributes::Builder B;
38713871 B.addAttribute(Attributes::NoUnwind);
38723872 AttrListPtr Attributes = AttrListPtr().addAttr(M->getContext(), ~0u,
3873 Attributes::get(B));
3873 Attributes::get(C, B));
38743874 RetainAutoreleaseCallee =
38753875 M->getOrInsertFunction("objc_retainAutorelease", FTy, Attributes);
38763876 }
38863886 Attributes::Builder B;
38873887 B.addAttribute(Attributes::NoUnwind);
38883888 AttrListPtr Attributes = AttrListPtr().addAttr(M->getContext(), ~0u,
3889 Attributes::get(B));
3889 Attributes::get(C, B));
38903890 RetainAutoreleaseRVCallee =
38913891 M->getOrInsertFunction("objc_retainAutoreleaseReturnValue", FTy,
38923892 Attributes);
349349 // It would be readonly too, except that it still may write to errno.
350350 Attributes::Builder B;
351351 B.addAttribute(Attributes::NoCapture);
352 CI->addAttribute(1, Attributes::get(B));
352 CI->addAttribute(1, Attributes::get(Callee->getContext(), B));
353353 }
354354
355355 return 0;
4040
4141 Module *M = B.GetInsertBlock()->getParent()->getParent();
4242 AttributeWithIndex AWI[2];
43 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
43 AWI[0] = AttributeWithIndex::get(M->getContext(), 1, Attributes::NoCapture);
4444 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
45 AWI[1] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
45 AWI[1] = AttributeWithIndex::get(M->getContext(), ~0u,
46 ArrayRef(AVs, 2));
4647
4748 LLVMContext &Context = B.GetInsertBlock()->getContext();
4849 Constant *StrLen = M->getOrInsertFunction("strlen", AttrListPtr::get(AWI),
6667
6768 Module *M = B.GetInsertBlock()->getParent()->getParent();
6869 AttributeWithIndex AWI[2];
69 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
70 AWI[0] = AttributeWithIndex::get(M->getContext(), 1, Attributes::NoCapture);
7071 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
71 AWI[1] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
72 AWI[1] = AttributeWithIndex::get(M->getContext(), ~0u,
73 ArrayRef(AVs, 2));
7274
7375 LLVMContext &Context = B.GetInsertBlock()->getContext();
7476 Constant *StrNLen = M->getOrInsertFunction("strnlen", AttrListPtr::get(AWI),
9496 Module *M = B.GetInsertBlock()->getParent()->getParent();
9597 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
9698 AttributeWithIndex AWI =
97 AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
99 AttributeWithIndex::get(M->getContext(), ~0u,
100 ArrayRef(AVs, 2));
98101
99102 Type *I8Ptr = B.getInt8PtrTy();
100103 Type *I32Ty = B.getInt32Ty();
116119
117120 Module *M = B.GetInsertBlock()->getParent()->getParent();
118121 AttributeWithIndex AWI[3];
119 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
120 AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture);
122 AWI[0] = AttributeWithIndex::get(M->getContext(), 1, Attributes::NoCapture);
123 AWI[1] = AttributeWithIndex::get(M->getContext(), 2, Attributes::NoCapture);
121124 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
122 AWI[2] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
125 AWI[2] = AttributeWithIndex::get(M->getContext(), ~0u,
126 ArrayRef(AVs, 2));
123127
124128 LLVMContext &Context = B.GetInsertBlock()->getContext();
125129 Value *StrNCmp = M->getOrInsertFunction("strncmp", AttrListPtr::get(AWI),
146150
147151 Module *M = B.GetInsertBlock()->getParent()->getParent();
148152 AttributeWithIndex AWI[2];
149 AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture);
150 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
153 AWI[0] = AttributeWithIndex::get(M->getContext(), 2, Attributes::NoCapture);
154 AWI[1] = AttributeWithIndex::get(M->getContext(), ~0u, Attributes::NoUnwind);
151155 Type *I8Ptr = B.getInt8PtrTy();
152156 Value *StrCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI),
153157 I8Ptr, I8Ptr, I8Ptr, NULL);
168172
169173 Module *M = B.GetInsertBlock()->getParent()->getParent();
170174 AttributeWithIndex AWI[2];
171 AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture);
172 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
175 AWI[0] = AttributeWithIndex::get(M->getContext(), 2, Attributes::NoCapture);
176 AWI[1] = AttributeWithIndex::get(M->getContext(), ~0u, Attributes::NoUnwind);
173177 Type *I8Ptr = B.getInt8PtrTy();
174178 Value *StrNCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI),
175179 I8Ptr, I8Ptr, I8Ptr,
192196
193197 Module *M = B.GetInsertBlock()->getParent()->getParent();
194198 AttributeWithIndex AWI;
195 AWI = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
199 AWI = AttributeWithIndex::get(M->getContext(), ~0u, Attributes::NoUnwind);
196200 LLVMContext &Context = B.GetInsertBlock()->getContext();
197201 Value *MemCpy = M->getOrInsertFunction("__memcpy_chk",
198202 AttrListPtr::get(AWI),
220224 Module *M = B.GetInsertBlock()->getParent()->getParent();
221225 AttributeWithIndex AWI;
222226 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
223 AWI = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
227 AWI = AttributeWithIndex::get(M->getContext(), ~0u,
228 ArrayRef(AVs, 2));
224229 LLVMContext &Context = B.GetInsertBlock()->getContext();
225230 Value *MemChr = M->getOrInsertFunction("memchr", AttrListPtr::get(AWI),
226231 B.getInt8PtrTy(),
245250
246251 Module *M = B.GetInsertBlock()->getParent()->getParent();
247252 AttributeWithIndex AWI[3];
248 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
249 AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture);
253 AWI[0] = AttributeWithIndex::get(M->getContext(), 1, Attributes::NoCapture);
254 AWI[1] = AttributeWithIndex::get(M->getContext(), 2, Attributes::NoCapture);
250255 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
251 AWI[2] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
256 AWI[2] = AttributeWithIndex::get(M->getContext(), ~0u,
257 ArrayRef(AVs, 2));
252258
253259 LLVMContext &Context = B.GetInsertBlock()->getContext();
254260 Value *MemCmp = M->getOrInsertFunction("memcmp", AttrListPtr::get(AWI),
324330
325331 Module *M = B.GetInsertBlock()->getParent()->getParent();
326332 AttributeWithIndex AWI[2];
327 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
328 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
333 AWI[0] = AttributeWithIndex::get(M->getContext(), 1, Attributes::NoCapture);
334 AWI[1] = AttributeWithIndex::get(M->getContext(), ~0u, Attributes::NoUnwind);
329335
330336 Value *PutS = M->getOrInsertFunction("puts", AttrListPtr::get(AWI),
331337 B.getInt32Ty(),
346352
347353 Module *M = B.GetInsertBlock()->getParent()->getParent();
348354 AttributeWithIndex AWI[2];
349 AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture);
350 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
355 AWI[0] = AttributeWithIndex::get(M->getContext(), 2, Attributes::NoCapture);
356 AWI[1] = AttributeWithIndex::get(M->getContext(), ~0u, Attributes::NoUnwind);
351357 Constant *F;
352358 if (File->getType()->isPointerTy())
353359 F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI),
377383
378384 Module *M = B.GetInsertBlock()->getParent()->getParent();
379385 AttributeWithIndex AWI[3];
380 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
381 AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture);
382 AWI[2] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
386 AWI[0] = AttributeWithIndex::get(M->getContext(), 1, Attributes::NoCapture);
387 AWI[1] = AttributeWithIndex::get(M->getContext(), 2, Attributes::NoCapture);
388 AWI[2] = AttributeWithIndex::get(M->getContext(), ~0u, Attributes::NoUnwind);
383389 StringRef FPutsName = TLI->getName(LibFunc::fputs);
384390 Constant *F;
385391 if (File->getType()->isPointerTy())
408414
409415 Module *M = B.GetInsertBlock()->getParent()->getParent();
410416 AttributeWithIndex AWI[3];
411 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
412 AWI[1] = AttributeWithIndex::get(4, Attributes::NoCapture);
413 AWI[2] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
417 AWI[0] = AttributeWithIndex::get(M->getContext(), 1, Attributes::NoCapture);
418 AWI[1] = AttributeWithIndex::get(M->getContext(), 4, Attributes::NoCapture);
419 AWI[2] = AttributeWithIndex::get(M->getContext(), ~0u, Attributes::NoUnwind);
414420 LLVMContext &Context = B.GetInsertBlock()->getContext();
415421 StringRef FWriteName = TLI->getName(LibFunc::fwrite);
416422 Constant *F;
2626 // Attributes Implementation
2727 //===----------------------------------------------------------------------===//
2828
29 Attributes::Attributes(uint64_t Val) : Attrs(Val) {}
30
31 Attributes::Attributes(LLVMContext &C, AttrVal Val)
32 : Attrs(Attributes::get(Attributes::Builder().addAttribute(Val)).Attrs) {}
33
34 Attributes::Attributes(AttributesImpl *A) : Attrs(A->Bits) {}
29 Attributes::Attributes(LLVMContext &C, ArrayRef Vals) {
30 Attributes::Builder B;
31 for (ArrayRef::iterator I = Vals.begin(), E = Vals.end();
32 I != E; ++I)
33 B.addAttribute(*I);
34 Attrs = Attributes::get(C, B).Attrs;
35 }
36
37 Attributes::Attributes(AttributesImpl *A) : Attrs(A) {}
3538
3639 Attributes::Attributes(const Attributes &A) : Attrs(A.Attrs) {}
37
38 // FIXME: This is temporary until we have implemented the uniquified version of
39 // AttributesImpl.
40 Attributes Attributes::get(Attributes::Builder &B) {
41 return Attributes(B.Bits);
42 }
4340
4441 Attributes Attributes::get(LLVMContext &Context, Attributes::Builder &B) {
4542 // If there are no attributes, return an empty Attributes class.
6663 }
6764
6865 bool Attributes::hasAttribute(AttrVal Val) const {
69 return Attrs.hasAttribute(Val);
66 return Attrs && Attrs->hasAttribute(Val);
7067 }
7168
7269 bool Attributes::hasAttributes(const Attributes &A) const {
73 return Attrs.hasAttributes(A);
70 return Attrs && Attrs->hasAttributes(A);
7471 }
7572
7673 /// This returns the alignment field of an attribute as a byte alignment value.
7774 unsigned Attributes::getAlignment() const {
7875 if (!hasAttribute(Attributes::Alignment))
7976 return 0;
80 return 1U << ((Attrs.getAlignment() >> 16) - 1);
77 return 1U << ((Attrs->getAlignment() >> 16) - 1);
8178 }
8279
8380 /// This returns the stack alignment field of an attribute as a byte alignment
8582 unsigned Attributes::getStackAlignment() const {
8683 if (!hasAttribute(Attributes::StackAlignment))
8784 return 0;
88 return 1U << ((Attrs.getStackAlignment() >> 26) - 1);
85 return 1U << ((Attrs->getStackAlignment() >> 26) - 1);
8986 }
9087
9188 uint64_t Attributes::Raw() const {
92 return Attrs.Bits;
89 return Attrs ? Attrs->Bits : 0; // FIXME: Don't access this directly!
9390 }
9491
9592 Attributes Attributes::typeIncompatible(Type *Ty) {
108105 .addAttribute(Attributes::NoCapture)
109106 .addAttribute(Attributes::StructRet);
110107
111 return Attributes(Incompatible.Bits); // FIXME: Use Attributes::get().
108 return Attributes::get(Ty->getContext(), Incompatible);
112109 }
113110
114111 std::string Attributes::getAsString() const {
513510 // If there are attributes already at this index, merge them in.
514511 if (i != e && OldAttrList[i].Index == Idx) {
515512 Attrs =
516 Attributes::get(Attributes::Builder(Attrs).
513 Attributes::get(C, Attributes::Builder(Attrs).
517514 addAttributes(OldAttrList[i].Attrs));
518515 ++i;
519516 }
554551
555552 // If there are attributes already at this index, merge them in.
556553 assert(OldAttrList[i].Index == Idx && "Attribute isn't set?");
557 Attrs = Attributes::get(Attributes::Builder(OldAttrList[i].Attrs).
554 Attrs = Attributes::get(C, Attributes::Builder(OldAttrList[i].Attrs).
558555 removeAttributes(Attrs));
559556 ++i;
560557 if (Attrs.hasAttributes()) // If any attributes left for this param, add them.
147147 if (NewFn)
148148 F = NewFn;
149149 if (unsigned id = F->getIntrinsicID())
150 F->setAttributes(Intrinsic::getAttributes((Intrinsic::ID)id));
150 F->setAttributes(Intrinsic::getAttributes(F->getContext(),
151 (Intrinsic::ID)id));
151152 return Upgraded;
152153 }
153154
13801380 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
13811381 Function *Func = unwrap(Fn);
13821382 const AttrListPtr PAL = Func->getAttributes();
1383 const AttrListPtr PALnew = PAL.addAttr(Func->getContext(), ~0U,
1384 Attributes(PA));
1383 Attributes::Builder B(PA);
1384 const AttrListPtr PALnew =
1385 PAL.addAttr(Func->getContext(), ~0U,
1386 Attributes::get(Func->getContext(), B));
13851387 Func->setAttributes(PALnew);
13861388 }
13871389
13881390 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
13891391 Function *Func = unwrap(Fn);
13901392 const AttrListPtr PAL = Func->getAttributes();
1391 const AttrListPtr PALnew = PAL.removeAttr(Func->getContext(), ~0U,
1392 Attributes(PA));
1393 Attributes::Builder B(PA);
1394 const AttrListPtr PALnew =
1395 PAL.removeAttr(Func->getContext(), ~0U,
1396 Attributes::get(Func->getContext(), B));
13931397 Func->setAttributes(PALnew);
13941398 }
13951399
14591463 }
14601464
14611465 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1462 unwrap(Arg)->addAttr(Attributes(PA));
1466 Argument *A = unwrap(Arg);
1467 Attributes::Builder B(PA);
1468 A->addAttr(Attributes::get(A->getContext(), B));
14631469 }
14641470
14651471 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1466 unwrap(Arg)->removeAttr(Attributes(PA));
1472 Argument *A = unwrap(Arg);
1473 Attributes::Builder B(PA);
1474 A->removeAttr(Attributes::get(A->getContext(), B));
14671475 }
14681476
14691477 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
14771485 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
14781486 Attributes::Builder B;
14791487 B.addAlignmentAttr(align);
1480 unwrap(Arg)->addAttr(Attributes::get(B));
1488 unwrap(Arg)->addAttr(Attributes::
1489 get(unwrap(Arg)->getContext(), B));
14811490 }
14821491
14831492 /*--.. Operations on basic blocks ..........................................--*/
16661675 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
16671676 LLVMAttribute PA) {
16681677 CallSite Call = CallSite(unwrap(Instr));
1678 Attributes::Builder B(PA);
16691679 Call.setAttributes(
1670 Call.getAttributes().addAttr(Call->getContext(), index, Attributes(PA)));
1680 Call.getAttributes().addAttr(Call->getContext(), index,
1681 Attributes::get(Call->getContext(), B)));
16711682 }
16721683
16731684 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
16741685 LLVMAttribute PA) {
16751686 CallSite Call = CallSite(unwrap(Instr));
1687 Attributes::Builder B(PA);
16761688 Call.setAttributes(
1677 Call.getAttributes().removeAttr(Call->getContext(), index, Attributes(PA)));
1689 Call.getAttributes().removeAttr(Call->getContext(), index,
1690 Attributes::get(Call->getContext(), B)));
16781691 }
16791692
16801693 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
16831696 Attributes::Builder B;
16841697 B.addAlignmentAttr(align);
16851698 Call.setAttributes(Call.getAttributes().addAttr(Call->getContext(), index,
1686 Attributes::get(B)));
1699 Attributes::get(Call->getContext(), B)));
16871700 }
16881701
16891702 /*--.. Operations on call instructions (only) ..............................--*/
184184
185185 // Ensure intrinsics have the right parameter attributes.
186186 if (unsigned IID = getIntrinsicID())
187 setAttributes(Intrinsic::getAttributes(Intrinsic::ID(IID)));
187 setAttributes(Intrinsic::getAttributes(getContext(), Intrinsic::ID(IID)));
188188
189189 }
190190
617617 Attributes::Builder NotFn(FAttrs);
618618 NotFn.removeFunctionOnlyAttrs();
619619 Assert1(!NotFn.hasAttributes(), "Attributes '" +
620 Attributes::get(NotFn).getAsString() +
620 Attributes::get(V->getContext(), NotFn).getAsString() +
621621 "' do not apply to the function!", V);
622622
623623 // Check for mutually incompatible attributes.
509509 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
510510 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
511511 if (TargetOnly)
512 OS << "static AttrListPtr getAttributes(" << TargetPrefix
512 OS << "static AttrListPtr getAttributes(LLVMContext &C, " << TargetPrefix
513513 << "Intrinsic::ID id) {\n";
514514 else
515 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {\n";
515 OS << "AttrListPtr Intrinsic::getAttributes(LLVMContext &C, ID id) {\n";
516516
517517 // Compute the maximum number of attribute arguments and the map
518518 typedef std::map
581581 ++ai;
582582 } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
583583
584 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get("
584 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(C, "
585585 << argNo+1 << ", AttrVec);\n";
586586 }
587587 }
605605 OS << " AttrVec.push_back(Attributes::ReadNone);\n";
606606 break;
607607 }
608 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, "
608 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(C, ~0, "
609609 << "AttrVec);\n";
610610 }
611611