llvm.org GIT mirror llvm / 3e2cbf9
Reverting 168457 git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168465 91177308-0d34-0410-b5e6-96231b3b80d8 Pawel Wodnicki 6 years ago
12 changed file(s) with 126 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
317317 FunctionIndex = ~0U
318318 };
319319 private:
320 /// @brief The attributes that we are managing. This can be null to represent
321 /// the empty attributes list.
320 /// AttrList - The attributes that we are managing. This can be null to
321 /// represent the empty attributes list.
322322 AttributeListImpl *AttrList;
323
324 /// @brief The attributes for the specified index are returned. Attributes
325 /// for the result are denoted with Idx = 0.
326 Attributes getAttributes(unsigned Idx) const;
327
328 explicit AttrListPtr(AttributeListImpl *LI) : AttrList(LI) {}
329323 public:
330324 AttrListPtr() : AttrList(0) {}
331 AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) {}
325 AttrListPtr(const AttrListPtr &P);
332326 const AttrListPtr &operator=(const AttrListPtr &RHS);
327 ~AttrListPtr();
333328
334329 //===--------------------------------------------------------------------===//
335330 // Attribute List Construction and Mutation
336331 //===--------------------------------------------------------------------===//
337332
338333 /// get - Return a Attributes list with the specified parameters in it.
339 static AttrListPtr get(LLVMContext &C, ArrayRef Attrs);
334 static AttrListPtr get(ArrayRef Attrs);
340335
341336 /// addAttr - Add the specified attribute at the specified index to this
342337 /// attribute list. Since attribute lists are immutable, this
423418 const AttributeWithIndex &getSlot(unsigned Slot) const;
424419
425420 void dump() const;
421
422 private:
423 explicit AttrListPtr(AttributeListImpl *L);
424
425 /// getAttributes - The attributes for the specified index are
426 /// returned. Attributes for the result are denoted with Idx = 0.
427 Attributes getAttributes(unsigned Idx) const;
426428 };
427429
428430 } // End llvm namespace
27932793 Attributes::get(RetType->getContext(),
27942794 FuncAttrs)));
27952795
2796 AttrListPtr PAL = AttrListPtr::get(Context, Attrs);
2796 AttrListPtr PAL = AttrListPtr::get(Attrs);
27972797
27982798 if (PAL.getParamAttributes(1).hasAttribute(Attributes::StructRet) &&
27992799 !RetType->isVoidTy())
33503350 FnAttrs)));
33513351
33523352 // Finish off the Attributes and check them
3353 AttrListPtr PAL = AttrListPtr::get(Context, Attrs);
3353 AttrListPtr PAL = AttrListPtr::get(Attrs);
33543354
33553355 InvokeInst *II = InvokeInst::Create(Callee, NormalBB, UnwindBB, Args);
33563356 II->setCallingConv(CC);
37523752 FnAttrs)));
37533753
37543754 // Finish off the Attributes and check them
3755 AttrListPtr PAL = AttrListPtr::get(Context, Attrs);
3755 AttrListPtr PAL = AttrListPtr::get(Attrs);
37563756
37573757 CallInst *CI = CallInst::Create(Callee, Args);
37583758 CI->setTailCall(isTail);
486486 Attributes::get(Context, B)));
487487 }
488488
489 MAttributes.push_back(AttrListPtr::get(Context, Attrs));
489 MAttributes.push_back(AttrListPtr::get(Attrs));
490490 Attrs.clear();
491491 break;
492492 }
610610
611611 // Recompute the parameter attributes list based on the new arguments for
612612 // the function.
613 NF->setAttributes(AttrListPtr::get(F->getContext(), AttributesVec));
613 NF->setAttributes(AttrListPtr::get(AttributesVec));
614614 AttributesVec.clear();
615615
616616 F->getParent()->getFunctionList().insert(F, NF);
730730 New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
731731 Args, "", Call);
732732 cast(New)->setCallingConv(CS.getCallingConv());
733 cast(New)->setAttributes(AttrListPtr::get(II->getContext(),
734 AttributesVec));
733 cast(New)->setAttributes(AttrListPtr::get(AttributesVec));
735734 } else {
736735 New = CallInst::Create(NF, Args, "", Call);
737736 cast(New)->setCallingConv(CS.getCallingConv());
738 cast(New)->setAttributes(AttrListPtr::get(New->getContext(),
739 AttributesVec));
737 cast(New)->setAttributes(AttrListPtr::get(AttributesVec));
740738 if (cast(Call)->isTailCall())
741739 cast(New)->setTailCall();
742740 }
279279 if (FnAttrs.hasAttributes())
280280 AttributesVec.push_back(AttributeWithIndex::get(AttrListPtr::FunctionIndex,
281281 FnAttrs));
282 PAL = AttrListPtr::get(Fn.getContext(), AttributesVec);
282 PAL = AttrListPtr::get(AttributesVec);
283283 }
284284
285285 Instruction *New;
805805 FnAttrs));
806806
807807 // Reconstruct the AttributesList based on the vector we constructed.
808 AttrListPtr NewPAL = AttrListPtr::get(F->getContext(), AttributesVec);
808 AttrListPtr NewPAL = AttrListPtr::get(AttributesVec);
809809
810810 // Create the new function type based on the recomputed parameters.
811811 FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg());
873873 FnAttrs));
874874
875875 // Reconstruct the AttributesList based on the vector we constructed.
876 AttrListPtr NewCallPAL = AttrListPtr::get(F->getContext(), AttributesVec);
876 AttrListPtr NewCallPAL = AttrListPtr::get(AttributesVec);
877877
878878 Instruction *New;
879879 if (InvokeInst *II = dyn_cast(Call)) {
11761176 if (NewRetTy->isVoidTy())
11771177 Caller->setName(""); // Void type should not have a name.
11781178
1179 const AttrListPtr &NewCallerPAL = AttrListPtr::get(Callee->getContext(),
1180 attrVec);
1179 const AttrListPtr &NewCallerPAL = AttrListPtr::get(attrVec);
11811180
11821181 Instruction *NC;
11831182 if (InvokeInst *II = dyn_cast(Caller)) {
13551354 NestF->getType() == PointerType::getUnqual(NewFTy) ?
13561355 NestF : ConstantExpr::getBitCast(NestF,
13571356 PointerType::getUnqual(NewFTy));
1358 const AttrListPtr &NewPAL = AttrListPtr::get(FTy->getContext(), NewAttrs);
1357 const AttrListPtr &NewPAL = AttrListPtr::get(NewAttrs);
13591358
13601359 Instruction *NewCaller;
13611360 if (InvokeInst *II = dyn_cast(Caller)) {
4646 ArrayRef(AVs, 2));
4747
4848 LLVMContext &Context = B.GetInsertBlock()->getContext();
49 Constant *StrLen = M->getOrInsertFunction("strlen",
50 AttrListPtr::get(M->getContext(),
51 AWI),
49 Constant *StrLen = M->getOrInsertFunction("strlen", AttrListPtr::get(AWI),
5250 TD->getIntPtrType(Context),
5351 B.getInt8PtrTy(),
5452 NULL);
7573 ArrayRef(AVs, 2));
7674
7775 LLVMContext &Context = B.GetInsertBlock()->getContext();
78 Constant *StrNLen = M->getOrInsertFunction("strnlen",
79 AttrListPtr::get(M->getContext(),
80 AWI),
76 Constant *StrNLen = M->getOrInsertFunction("strnlen", AttrListPtr::get(AWI),
8177 TD->getIntPtrType(Context),
8278 B.getInt8PtrTy(),
8379 TD->getIntPtrType(Context),
105101
106102 Type *I8Ptr = B.getInt8PtrTy();
107103 Type *I32Ty = B.getInt32Ty();
108 Constant *StrChr = M->getOrInsertFunction("strchr",
109 AttrListPtr::get(M->getContext(),
110 AWI),
104 Constant *StrChr = M->getOrInsertFunction("strchr", AttrListPtr::get(AWI),
111105 I8Ptr, I8Ptr, I32Ty, NULL);
112106 CallInst *CI = B.CreateCall2(StrChr, CastToCStr(Ptr, B),
113107 ConstantInt::get(I32Ty, C), "strchr");
132126 ArrayRef(AVs, 2));
133127
134128 LLVMContext &Context = B.GetInsertBlock()->getContext();
135 Value *StrNCmp = M->getOrInsertFunction("strncmp",
136 AttrListPtr::get(M->getContext(),
137 AWI),
129 Value *StrNCmp = M->getOrInsertFunction("strncmp", AttrListPtr::get(AWI),
138130 B.getInt32Ty(),
139131 B.getInt8PtrTy(),
140132 B.getInt8PtrTy(),
162154 AWI[1] = AttributeWithIndex::get(M->getContext(), AttrListPtr::FunctionIndex,
163155 Attributes::NoUnwind);
164156 Type *I8Ptr = B.getInt8PtrTy();
165 Value *StrCpy = M->getOrInsertFunction(Name,
166 AttrListPtr::get(M->getContext(), AWI),
157 Value *StrCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI),
167158 I8Ptr, I8Ptr, I8Ptr, NULL);
168159 CallInst *CI = B.CreateCall2(StrCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
169160 Name);
186177 AWI[1] = AttributeWithIndex::get(M->getContext(), AttrListPtr::FunctionIndex,
187178 Attributes::NoUnwind);
188179 Type *I8Ptr = B.getInt8PtrTy();
189 Value *StrNCpy = M->getOrInsertFunction(Name,
190 AttrListPtr::get(M->getContext(),
191 AWI),
180 Value *StrNCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI),
192181 I8Ptr, I8Ptr, I8Ptr,
193182 Len->getType(), NULL);
194183 CallInst *CI = B.CreateCall3(StrNCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
213202 Attributes::NoUnwind);
214203 LLVMContext &Context = B.GetInsertBlock()->getContext();
215204 Value *MemCpy = M->getOrInsertFunction("__memcpy_chk",
216 AttrListPtr::get(M->getContext(), AWI),
205 AttrListPtr::get(AWI),
217206 B.getInt8PtrTy(),
218207 B.getInt8PtrTy(),
219208 B.getInt8PtrTy(),
241230 AWI = AttributeWithIndex::get(M->getContext(), AttrListPtr::FunctionIndex,
242231 ArrayRef(AVs, 2));
243232 LLVMContext &Context = B.GetInsertBlock()->getContext();
244 Value *MemChr = M->getOrInsertFunction("memchr",
245 AttrListPtr::get(M->getContext(), AWI),
233 Value *MemChr = M->getOrInsertFunction("memchr", AttrListPtr::get(AWI),
246234 B.getInt8PtrTy(),
247235 B.getInt8PtrTy(),
248236 B.getInt32Ty(),
272260 ArrayRef(AVs, 2));
273261
274262 LLVMContext &Context = B.GetInsertBlock()->getContext();
275 Value *MemCmp = M->getOrInsertFunction("memcmp",
276 AttrListPtr::get(M->getContext(), AWI),
263 Value *MemCmp = M->getOrInsertFunction("memcmp", AttrListPtr::get(AWI),
277264 B.getInt32Ty(),
278265 B.getInt8PtrTy(),
279266 B.getInt8PtrTy(),
350337 AWI[1] = AttributeWithIndex::get(M->getContext(), AttrListPtr::FunctionIndex,
351338 Attributes::NoUnwind);
352339
353 Value *PutS = M->getOrInsertFunction("puts",
354 AttrListPtr::get(M->getContext(), AWI),
340 Value *PutS = M->getOrInsertFunction("puts", AttrListPtr::get(AWI),
355341 B.getInt32Ty(),
356342 B.getInt8PtrTy(),
357343 NULL);
375361 Attributes::NoUnwind);
376362 Constant *F;
377363 if (File->getType()->isPointerTy())
378 F = M->getOrInsertFunction("fputc",
379 AttrListPtr::get(M->getContext(), AWI),
364 F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI),
380365 B.getInt32Ty(),
381366 B.getInt32Ty(), File->getType(),
382367 NULL);
410395 StringRef FPutsName = TLI->getName(LibFunc::fputs);
411396 Constant *F;
412397 if (File->getType()->isPointerTy())
413 F = M->getOrInsertFunction(FPutsName,
414 AttrListPtr::get(M->getContext(), AWI),
398 F = M->getOrInsertFunction(FPutsName, AttrListPtr::get(AWI),
415399 B.getInt32Ty(),
416400 B.getInt8PtrTy(),
417401 File->getType(), NULL);
444428 StringRef FWriteName = TLI->getName(LibFunc::fwrite);
445429 Constant *F;
446430 if (File->getType()->isPointerTy())
447 F = M->getOrInsertFunction(FWriteName,
448 AttrListPtr::get(M->getContext(), AWI),
431 F = M->getOrInsertFunction(FWriteName, AttrListPtr::get(AWI),
449432 TD->getIntPtrType(Context),
450433 B.getInt8PtrTy(),
451434 TD->getIntPtrType(Context),
354354 // AttributeListImpl Definition
355355 //===----------------------------------------------------------------------===//
356356
357 AttrListPtr AttrListPtr::get(LLVMContext &C,
358 ArrayRef Attrs) {
357 namespace llvm {
358 class AttributeListImpl;
359 }
360
361 static ManagedStatic > AttributesLists;
362
363 namespace llvm {
364 static ManagedStatic > ALMutex;
365
366 class AttributeListImpl : public FoldingSetNode {
367 sys::cas_flag RefCount;
368
369 // AttributesList is uniqued, these should not be publicly available.
370 void operator=(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
371 AttributeListImpl(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
372 ~AttributeListImpl(); // Private implementation
373 public:
374 SmallVector Attrs;
375
376 AttributeListImpl(ArrayRef attrs)
377 : Attrs(attrs.begin(), attrs.end()) {
378 RefCount = 0;
379 }
380
381 void AddRef() {
382 sys::SmartScopedLock Lock(*ALMutex);
383 ++RefCount;
384 }
385 void DropRef() {
386 sys::SmartScopedLock Lock(*ALMutex);
387 if (!AttributesLists.isConstructed())
388 return;
389 sys::cas_flag new_val = --RefCount;
390 if (new_val == 0)
391 delete this;
392 }
393
394 void Profile(FoldingSetNodeID &ID) const {
395 Profile(ID, Attrs);
396 }
397 static void Profile(FoldingSetNodeID &ID, ArrayRef Attrs){
398 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
399 ID.AddInteger(Attrs[i].Attrs.Raw());
400 ID.AddInteger(Attrs[i].Index);
401 }
402 }
403 };
404
405 } // end llvm namespace
406
407 AttributeListImpl::~AttributeListImpl() {
408 // NOTE: Lock must be acquired by caller.
409 AttributesLists->RemoveNode(this);
410 }
411
412 AttrListPtr AttrListPtr::get(ArrayRef Attrs) {
359413 // If there are no attributes then return a null AttributesList pointer.
360414 if (Attrs.empty())
361415 return AttrListPtr();
370424 #endif
371425
372426 // Otherwise, build a key to look up the existing attributes.
373 LLVMContextImpl *pImpl = C.pImpl;
374427 FoldingSetNodeID ID;
375428 AttributeListImpl::Profile(ID, Attrs);
376
377 void *InsertPoint;
378 AttributeListImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID,
379 InsertPoint);
429 void *InsertPos;
430
431 sys::SmartScopedLock Lock(*ALMutex);
432
433 AttributeListImpl *PAL =
434 AttributesLists->FindNodeOrInsertPos(ID, InsertPos);
380435
381436 // If we didn't find any existing attributes of the same shape then
382437 // create a new one and insert it.
383 if (!PA) {
384 PA = new AttributeListImpl(Attrs);
385 pImpl->AttrsLists.InsertNode(PA, InsertPoint);
438 if (!PAL) {
439 PAL = new AttributeListImpl(Attrs);
440 AttributesLists->InsertNode(PAL, InsertPos);
386441 }
387442
388443 // Return the AttributesList that we found or created.
389 return AttrListPtr(PA);
444 return AttrListPtr(PAL);
390445 }
391446
392447 //===----------------------------------------------------------------------===//
393448 // AttrListPtr Method Implementations
394449 //===----------------------------------------------------------------------===//
395450
451 AttrListPtr::AttrListPtr(AttributeListImpl *LI) : AttrList(LI) {
452 if (LI) LI->AddRef();
453 }
454
455 AttrListPtr::AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) {
456 if (AttrList) AttrList->AddRef();
457 }
458
396459 const AttrListPtr &AttrListPtr::operator=(const AttrListPtr &RHS) {
460 sys::SmartScopedLock Lock(*ALMutex);
397461 if (AttrList == RHS.AttrList) return *this;
398
462 if (AttrList) AttrList->DropRef();
399463 AttrList = RHS.AttrList;
400 return *this;
464 if (AttrList) AttrList->AddRef();
465 return *this;
466 }
467
468 AttrListPtr::~AttrListPtr() {
469 if (AttrList) AttrList->DropRef();
401470 }
402471
403472 /// getNumSlots - Return the number of slots used in this attribute list.
437506 for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
438507 if (Attrs[i].Attrs.hasAttribute(Attr))
439508 return true;
440
441509 return false;
442510 }
443511
493561 OldAttrList.begin()+i, OldAttrList.end());
494562 }
495563
496 return get(C, NewAttrList);
564 return get(NewAttrList);
497565 }
498566
499567 AttrListPtr AttrListPtr::removeAttr(LLVMContext &C, unsigned Idx,
532600 NewAttrList.insert(NewAttrList.end(),
533601 OldAttrList.begin()+i, OldAttrList.end());
534602
535 return get(C, NewAttrList);
603 return get(NewAttrList);
536604 }
537605
538606 void AttrListPtr::dump() const {
1414 #ifndef LLVM_ATTRIBUTESIMPL_H
1515 #define LLVM_ATTRIBUTESIMPL_H
1616
17 #include "llvm/Attributes.h"
1817 #include "llvm/ADT/FoldingSet.h"
1918
2019 namespace llvm {
20
21 class Attributes;
2122
2223 class AttributesImpl : public FoldingSetNode {
2324 uint64_t Bits; // FIXME: We will be expanding this.
4445 }
4546 };
4647
47 class AttributeListImpl : public FoldingSetNode {
48 // AttributesList is uniqued, these should not be publicly available.
49 void operator=(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
50 AttributeListImpl(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
51 public:
52 SmallVector Attrs;
53
54 AttributeListImpl(ArrayRef attrs)
55 : Attrs(attrs.begin(), attrs.end()) {}
56
57 void Profile(FoldingSetNodeID &ID) const {
58 Profile(ID, Attrs);
59 }
60 static void Profile(FoldingSetNodeID &ID, ArrayRef Attrs){
61 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
62 ID.AddInteger(Attrs[i].Attrs.Raw());
63 ID.AddInteger(Attrs[i].Index);
64 }
65 }
66 };
67
6848 } // end llvm namespace
6949
7050 #endif
9696
9797 // Destroy attributes.
9898 for (FoldingSetIterator I = AttrsSet.begin(),
99 E = AttrsSet.end(); I != E; ) {
99 E = AttrsSet.end(); I != E;) {
100100 FoldingSetIterator Elem = I++;
101 delete &*Elem;
102 }
103
104 // Destroy attribute lists.
105 for (FoldingSetIterator I = AttrsLists.begin(),
106 E = AttrsLists.end(); I != E; ) {
107 FoldingSetIterator Elem = I++;
108101 delete &*Elem;
109102 }
110103
255255 FPMapTy FPConstants;
256256
257257 FoldingSet AttrsSet;
258 FoldingSet AttrsLists;
259
258
260259 StringMap MDStringCache;
261260
262261 FoldingSet MDNodeSet;
620620
621621 OS << " }\n";
622622 OS << " }\n";
623 OS << " return AttrListPtr::get(C, ArrayRef(AWI, "
623 OS << " return AttrListPtr::get(ArrayRef(AWI, "
624624 "NumAttrs));\n";
625625 OS << "}\n";
626626 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";