llvm.org GIT mirror llvm / 11d0042
Pass into the AttributeWithIndex::get method an ArrayRef of attribute enums. These are then created via the correct Attributes creation method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165607 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 8 years ago
4 changed file(s) with 99 addition(s) and 88 deletion(s). Raw diff Collapse all Expand all
9696
9797 #undef DECLARE_LLVM_ATTRIBUTE
9898
99 /// Note that uwtable is about the ABI or the user mandating an entry in the
100 /// unwind table. The nounwind attribute is about an exception passing by the
101 /// function.
102 /// In a theoretical system that uses tables for profiling and sjlj for
103 /// exceptions, they would be fully independent. In a normal system that
104 /// uses tables for both, the semantics are:
105 /// nil = Needs an entry because an exception might pass by.
106 /// nounwind = No need for an entry
107 /// uwtable = Needs an entry because the ABI says so and because
108 /// an exception might pass by.
109 /// uwtable + nounwind = Needs an entry because the ABI says so.
110
11199 } // namespace Attribute
112100
113101 /// AttributeImpl - The internal representation of the Attributes class. This is
117105 /// Attributes - A bitset of attributes.
118106 class Attributes {
119107 public:
108 /// Note that uwtable is about the ABI or the user mandating an entry in the
109 /// unwind table. The nounwind attribute is about an exception passing by the
110 /// function.
111 ///
112 /// In a theoretical system that uses tables for profiling and sjlj for
113 /// exceptions, they would be fully independent. In a normal system that uses
114 /// tables for both, the semantics are:
115 ///
116 /// nil = Needs an entry because an exception might pass by.
117 /// nounwind = No need for an entry
118 /// uwtable = Needs an entry because the ABI says so and because
119 /// an exception might pass by.
120 /// uwtable + nounwind = Needs an entry because the ABI says so.
121
120122 enum AttrVal {
121123 None = 0, ///< No attributes have been set
122124 AddressSafety = 1, ///< Address safety checking is on.
374376 ///< Index 0 is used for return value attributes.
375377 ///< Index ~0U is used for function attributes.
376378
379 static AttributeWithIndex get(unsigned Idx,
380 ArrayRef Attrs) {
381 Attributes::Builder B;
382
383 for (ArrayRef::iterator I = Attrs.begin(),
384 E = Attrs.end(); I != E; ++I)
385 B.addAttribute(*I);
386
387 AttributeWithIndex P;
388 P.Index = Idx;
389 P.Attrs = Attributes::get(B);
390 return P;
391 }
377392 static AttributeWithIndex get(unsigned Idx, Attributes Attrs) {
378393 AttributeWithIndex P;
379394 P.Index = Idx;
276276 bool doesNotAlias(unsigned n) const {
277277 return getParamAttributes(n).hasAttribute(Attributes::NoAlias);
278278 }
279 void setDoesNotAlias(unsigned n, bool DoesNotAlias = true) {
280 if (DoesNotAlias) addAttribute(n, Attribute::NoAlias);
281 else removeAttribute(n, Attribute::NoAlias);
279 void setDoesNotAlias(unsigned n) {
280 Attributes::Builder B;
281 B.addAttribute(Attributes::NoAlias);
282 addAttribute(n, Attributes::get(B));
282283 }
283284
284285 /// @brief Determine if the parameter can be captured.
286287 bool doesNotCapture(unsigned n) const {
287288 return getParamAttributes(n).hasAttribute(Attributes::NoCapture);
288289 }
289 void setDoesNotCapture(unsigned n, bool DoesNotCapture = true) {
290 if (DoesNotCapture) addAttribute(n, Attribute::NoCapture);
291 else removeAttribute(n, Attribute::NoCapture);
290 void setDoesNotCapture(unsigned n) {
291 Attributes::Builder B;
292 B.addAttribute(Attributes::NoCapture);
293 addAttribute(n, Attributes::get(B));
292294 }
293295
294296 /// copyAttributesFrom - copy all additional attributes (those not needed to
4040
4141 Module *M = B.GetInsertBlock()->getParent()->getParent();
4242 AttributeWithIndex AWI[2];
43 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
44 AWI[1] = AttributeWithIndex::get(~0u, Attribute::ReadOnly |
45 Attribute::NoUnwind);
43 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
44 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
45 AWI[1] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
4646
4747 LLVMContext &Context = B.GetInsertBlock()->getContext();
4848 Constant *StrLen = M->getOrInsertFunction("strlen", AttrListPtr::get(AWI),
6666
6767 Module *M = B.GetInsertBlock()->getParent()->getParent();
6868 AttributeWithIndex AWI[2];
69 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
70 AWI[1] = AttributeWithIndex::get(~0u, Attribute::ReadOnly |
71 Attribute::NoUnwind);
69 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
70 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
71 AWI[1] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
7272
7373 LLVMContext &Context = B.GetInsertBlock()->getContext();
7474 Constant *StrNLen = M->getOrInsertFunction("strnlen", AttrListPtr::get(AWI),
9292 return 0;
9393
9494 Module *M = B.GetInsertBlock()->getParent()->getParent();
95 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
9596 AttributeWithIndex AWI =
96 AttributeWithIndex::get(~0u, Attribute::ReadOnly | Attribute::NoUnwind);
97 AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
9798
9899 Type *I8Ptr = B.getInt8PtrTy();
99100 Type *I32Ty = B.getInt32Ty();
115116
116117 Module *M = B.GetInsertBlock()->getParent()->getParent();
117118 AttributeWithIndex AWI[3];
118 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
119 AWI[1] = AttributeWithIndex::get(2, Attribute::NoCapture);
120 AWI[2] = AttributeWithIndex::get(~0u, Attribute::ReadOnly |
121 Attribute::NoUnwind);
119 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
120 AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture);
121 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
122 AWI[2] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
122123
123124 LLVMContext &Context = B.GetInsertBlock()->getContext();
124125 Value *StrNCmp = M->getOrInsertFunction("strncmp", AttrListPtr::get(AWI),
145146
146147 Module *M = B.GetInsertBlock()->getParent()->getParent();
147148 AttributeWithIndex AWI[2];
148 AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture);
149 AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
149 AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture);
150 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
150151 Type *I8Ptr = B.getInt8PtrTy();
151152 Value *StrCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI),
152153 I8Ptr, I8Ptr, I8Ptr, NULL);
167168
168169 Module *M = B.GetInsertBlock()->getParent()->getParent();
169170 AttributeWithIndex AWI[2];
170 AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture);
171 AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
171 AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture);
172 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
172173 Type *I8Ptr = B.getInt8PtrTy();
173174 Value *StrNCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI),
174175 I8Ptr, I8Ptr, I8Ptr,
191192
192193 Module *M = B.GetInsertBlock()->getParent()->getParent();
193194 AttributeWithIndex AWI;
194 AWI = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
195 AWI = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
195196 LLVMContext &Context = B.GetInsertBlock()->getContext();
196197 Value *MemCpy = M->getOrInsertFunction("__memcpy_chk",
197198 AttrListPtr::get(AWI),
218219
219220 Module *M = B.GetInsertBlock()->getParent()->getParent();
220221 AttributeWithIndex AWI;
221 AWI = AttributeWithIndex::get(~0u, Attribute::ReadOnly | Attribute::NoUnwind);
222 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
223 AWI = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
222224 LLVMContext &Context = B.GetInsertBlock()->getContext();
223225 Value *MemChr = M->getOrInsertFunction("memchr", AttrListPtr::get(AWI),
224226 B.getInt8PtrTy(),
243245
244246 Module *M = B.GetInsertBlock()->getParent()->getParent();
245247 AttributeWithIndex AWI[3];
246 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
247 AWI[1] = AttributeWithIndex::get(2, Attribute::NoCapture);
248 AWI[2] = AttributeWithIndex::get(~0u, Attribute::ReadOnly |
249 Attribute::NoUnwind);
248 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
249 AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture);
250 Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind };
251 AWI[2] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2));
250252
251253 LLVMContext &Context = B.GetInsertBlock()->getContext();
252254 Value *MemCmp = M->getOrInsertFunction("memcmp", AttrListPtr::get(AWI),
322324
323325 Module *M = B.GetInsertBlock()->getParent()->getParent();
324326 AttributeWithIndex AWI[2];
325 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
326 AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
327 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
328 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
327329
328330 Value *PutS = M->getOrInsertFunction("puts", AttrListPtr::get(AWI),
329331 B.getInt32Ty(),
344346
345347 Module *M = B.GetInsertBlock()->getParent()->getParent();
346348 AttributeWithIndex AWI[2];
347 AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture);
348 AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
349 AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture);
350 AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
349351 Constant *F;
350352 if (File->getType()->isPointerTy())
351353 F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI),
375377
376378 Module *M = B.GetInsertBlock()->getParent()->getParent();
377379 AttributeWithIndex AWI[3];
378 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
379 AWI[1] = AttributeWithIndex::get(2, Attribute::NoCapture);
380 AWI[2] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
380 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
381 AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture);
382 AWI[2] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
381383 StringRef FPutsName = TLI->getName(LibFunc::fputs);
382384 Constant *F;
383385 if (File->getType()->isPointerTy())
406408
407409 Module *M = B.GetInsertBlock()->getParent()->getParent();
408410 AttributeWithIndex AWI[3];
409 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
410 AWI[1] = AttributeWithIndex::get(4, Attribute::NoCapture);
411 AWI[2] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
411 AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture);
412 AWI[1] = AttributeWithIndex::get(4, Attributes::NoCapture);
413 AWI[2] = AttributeWithIndex::get(~0u, Attributes::NoUnwind);
412414 LLVMContext &Context = B.GetInsertBlock()->getContext();
413415 StringRef FWriteName = TLI->getName(LibFunc::fwrite);
414416 Constant *F;
546546 OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n";
547547 OS << " unsigned NumAttrs = 0;\n";
548548 OS << " if (id != 0) {\n";
549 OS << " SmallVector AttrVec;\n";
549550 OS << " switch(IntrinsicsToAttributesMap[id - ";
550551 if (TargetOnly)
551552 OS << "Intrinsic::num_intrinsics";
563564 unsigned numAttrs = 0;
564565
565566 // The argument attributes are alreadys sorted by argument index.
566 for (unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); ai != ae;) {
567 unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
568
569 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get("
570 << argNo+1 << ", ";
571
572 bool moreThanOne = false;
573
574 do {
575 if (moreThanOne) OS << '|';
576
577 switch (intrinsic.ArgumentAttributes[ai].second) {
578 case CodeGenIntrinsic::NoCapture:
579 OS << "Attribute::NoCapture";
580 break;
581 }
582
583 ++ai;
584 moreThanOne = true;
585 } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
586
587 OS << ");\n";
567 unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size();
568 if (ae) {
569 while (ai != ae) {
570 unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
571
572 OS << " AttrVec.clear();\n";
573
574 do {
575 switch (intrinsic.ArgumentAttributes[ai].second) {
576 case CodeGenIntrinsic::NoCapture:
577 OS << " AttrVec.push_back(Attributes::NoCapture);\n";
578 break;
579 }
580
581 ++ai;
582 } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
583
584 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get("
585 << argNo+1 << ", AttrVec);\n";
586 }
588587 }
589588
590589 ModRefKind modRef = getModRefKind(intrinsic);
591590
592591 if (!intrinsic.canThrow || modRef || intrinsic.isNoReturn) {
593 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, ";
594 bool Emitted = false;
595 if (!intrinsic.canThrow) {
596 OS << "Attribute::NoUnwind";
597 Emitted = true;
598 }
599
600 if (intrinsic.isNoReturn) {
601 if (Emitted) OS << '|';
602 OS << "Attribute::NoReturn";
603 Emitted = true;
604 }
592 OS << " AttrVec.clear();\n";
593
594 if (!intrinsic.canThrow)
595 OS << " AttrVec.push_back(Attributes::NoUnwind);\n";
596 if (intrinsic.isNoReturn)
597 OS << " AttrVec.push_back(Attributes::NoReturn);\n";
605598
606599 switch (modRef) {
607600 case MRK_none: break;
608601 case MRK_readonly:
609 if (Emitted) OS << '|';
610 OS << "Attribute::ReadOnly";
602 OS << " AttrVec.push_back(Attributes::ReadOnly);\n";
611603 break;
612604 case MRK_readnone:
613 if (Emitted) OS << '|';
614 OS << "Attribute::ReadNone";
605 OS << " AttrVec.push_back(Attributes::ReadNone);\n";
615606 break;
616607 }
617 OS << ");\n";
608 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, "
609 << "AttrVec);\n";
618610 }
619611
620612 if (numAttrs) {