llvm.org GIT mirror llvm / 7d2f249
Remove the final bits of Attributes being declared in the Attribute namespace. Use the attribute's enum value instead. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165610 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 8 years ago
8 changed file(s) with 61 addition(s) and 69 deletion(s). Raw diff Collapse all Expand all
5353 /// keep type-safety of Attributes.
5454 #define DECLARE_LLVM_ATTRIBUTE(name, value) \
5555 const AttrConst name = {value};
56
57 DECLARE_LLVM_ATTRIBUTE(None,0) ///< No attributes have been set
58 DECLARE_LLVM_ATTRIBUTE(ZExt,1<<0) ///< Zero extended before/after call
59 DECLARE_LLVM_ATTRIBUTE(SExt,1<<1) ///< Sign extended before/after call
60 DECLARE_LLVM_ATTRIBUTE(NoReturn,1<<2) ///< Mark the function as not returning
61 DECLARE_LLVM_ATTRIBUTE(InReg,1<<3) ///< Force argument to be passed in register
62 DECLARE_LLVM_ATTRIBUTE(StructRet,1<<4) ///< Hidden pointer to structure to return
63 DECLARE_LLVM_ATTRIBUTE(NoUnwind,1<<5) ///< Function doesn't unwind stack
64 DECLARE_LLVM_ATTRIBUTE(NoAlias,1<<6) ///< Considered to not alias after call
65 DECLARE_LLVM_ATTRIBUTE(ByVal,1<<7) ///< Pass structure by value
66 DECLARE_LLVM_ATTRIBUTE(Nest,1<<8) ///< Nested function static chain
67 DECLARE_LLVM_ATTRIBUTE(ReadNone,1<<9) ///< Function does not access memory
68 DECLARE_LLVM_ATTRIBUTE(ReadOnly,1<<10) ///< Function only reads from memory
69 DECLARE_LLVM_ATTRIBUTE(NoInline,1<<11) ///< inline=never
70 DECLARE_LLVM_ATTRIBUTE(AlwaysInline,1<<12) ///< inline=always
71 DECLARE_LLVM_ATTRIBUTE(OptimizeForSize,1<<13) ///< opt_size
72 DECLARE_LLVM_ATTRIBUTE(StackProtect,1<<14) ///< Stack protection.
73 DECLARE_LLVM_ATTRIBUTE(StackProtectReq,1<<15) ///< Stack protection required.
74 DECLARE_LLVM_ATTRIBUTE(Alignment,31<<16) ///< Alignment of parameter (5 bits)
75 // stored as log2 of alignment with +1 bias
76 // 0 means unaligned different from align 1
77 DECLARE_LLVM_ATTRIBUTE(NoCapture,1<<21) ///< Function creates no aliases of pointer
78 DECLARE_LLVM_ATTRIBUTE(NoRedZone,1<<22) /// disable redzone
79 DECLARE_LLVM_ATTRIBUTE(NoImplicitFloat,1<<23) /// disable implicit floating point
80 /// instructions.
81 DECLARE_LLVM_ATTRIBUTE(Naked,1<<24) ///< Naked function
82 DECLARE_LLVM_ATTRIBUTE(InlineHint,1<<25) ///< source said inlining was
83 ///desirable
84 DECLARE_LLVM_ATTRIBUTE(StackAlignment,7<<26) ///< Alignment of stack for
85 ///function (3 bits) stored as log2
86 ///of alignment with +1 bias
87 ///0 means unaligned (different from
88 ///alignstack= {1))
89 DECLARE_LLVM_ATTRIBUTE(ReturnsTwice,1<<29) ///< Function can return twice
90 DECLARE_LLVM_ATTRIBUTE(UWTable,1<<30) ///< Function must be in a unwind
91 ///table
92 DECLARE_LLVM_ATTRIBUTE(NonLazyBind,1U<<31) ///< Function is called early and/or
93 /// often, so lazy binding isn't
94 /// worthwhile.
95 DECLARE_LLVM_ATTRIBUTE(AddressSafety,1ULL<<32) ///< Address safety checking is on.
9656
9757 #undef DECLARE_LLVM_ATTRIBUTE
9858
174134
175135 void clear() { Bits = 0; }
176136
137 bool hasAttribute(Attributes::AttrVal A) const;
177138 bool hasAttributes() const;
178139 bool hasAttributes(const Attributes &A) const;
179140 bool hasAlignmentAttr() const;
180141
181142 uint64_t getAlignment() const;
143 uint64_t getStackAlignment() const;
182144
183145 Builder &addAttribute(Attributes::AttrVal Val);
184146 Builder &removeAttribute(Attributes::AttrVal Val);
466428
467429 /// hasAttrSomewhere - Return true if the specified attribute is set for at
468430 /// least one parameter or for the return value.
469 bool hasAttrSomewhere(Attributes Attr) const;
431 bool hasAttrSomewhere(Attributes::AttrVal Attr) const;
470432
471433 unsigned getNumAttrs() const;
472434 Attributes &getAttributesAtIndex(unsigned i) const;
313313 // the return. Ignore noalias because it doesn't affect the call sequence.
314314 const Function *F = ExitBB->getParent();
315315 Attributes CallerRetAttr = F->getAttributes().getRetAttributes();
316 if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias)
316 if (Attributes::Builder(CalleeRetAttr ^ CallerRetAttr)
317 .removeAttribute(Attributes::NoAlias).hasAttributes())
317318 return false;
318319
319320 // It's not safe to eliminate the sign / zero extension of the return value.
354355 // Conservatively require the attributes of the call to match those of
355356 // the return. Ignore noalias because it doesn't affect the call sequence.
356357 Attributes CallerRetAttr = F->getAttributes().getRetAttributes();
357 if (CallerRetAttr & ~Attribute::NoAlias)
358 if (Attributes::Builder(CallerRetAttr)
359 .removeAttribute(Attributes::NoAlias).hasAttributes())
358360 return false;
359361
360362 // It's not safe to eliminate the sign / zero extension of the return value.
473473 Out << "AttributeWithIndex PAWI;"; nl(Out);
474474 for (unsigned i = 0; i < PAL.getNumSlots(); ++i) {
475475 unsigned index = PAL.getSlot(i).Index;
476 Attributes attrs = PAL.getSlot(i).Attrs;
477 Out << "PAWI.Index = " << index << "U; PAWI.Attrs = Attribute::None ";
478 #define HANDLE_ATTR(X) \
479 if (attrs & Attribute::X) \
480 Out << " | Attribute::" #X; \
481 attrs &= ~Attribute::X;
482
476 Attributes::Builder attrs(PAL.getSlot(i).Attrs);
477 Out << "PAWI.Index = " << index << "U;\n";
478 Out << " Attributes::Builder B;\n";
479
480 #define HANDLE_ATTR(X) \
481 if (attrs.hasAttribute(Attributes::X)) \
482 Out << " B.addAttribute(Attributes::" #X ");\n"; \
483 attrs.removeAttribute(Attributes::X);
484
483485 HANDLE_ATTR(SExt);
484486 HANDLE_ATTR(ZExt);
485487 HANDLE_ATTR(NoReturn);
505507 HANDLE_ATTR(UWTable);
506508 HANDLE_ATTR(NonLazyBind);
507509 #undef HANDLE_ATTR
508 if (attrs & Attribute::StackAlignment)
509 Out << " | Attribute::constructStackAlignmentFromInt("
510 if (attrs.hasAttribute(Attributes::StackAlignment))
511 Out << "B.addStackAlignmentAttr(Attribute::constructStackAlignmentFromInt("
510512 << attrs.getStackAlignment()
511 << ")";
512 attrs &= ~Attribute::StackAlignment;
513 assert(attrs == 0 && "Unhandled attribute!");
514 Out << ";";
513 << "))";
514 nl(Out);
515 attrs.removeAttribute(Attributes::StackAlignment);
516 assert(!attrs.hasAttributes() && "Unhandled attribute!");
517 Out << "PAWI.Attrs = Attributes::get(B);";
515518 nl(Out);
516519 Out << "Attrs.push_back(PAWI);";
517520 nl(Out);
211211 MadeChange = true;
212212
213213 // Clear out any existing attributes.
214 F->removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
214 Attributes::Builder B;
215 B.addAttribute(Attributes::ReadOnly)
216 .addAttribute(Attributes::ReadNone);
217 F->removeAttribute(~0, Attributes::get(B));
215218
216219 // Add in the new attribute.
217 F->addAttribute(~0, ReadsMemory? Attribute::ReadOnly : Attribute::ReadNone);
220 B.clear();
221 B.addAttribute(ReadsMemory ? Attributes::ReadOnly : Attributes::ReadNone);
222 F->addAttribute(~0, Attributes::get(B));
218223
219224 if (ReadsMemory)
220225 ++NumReadOnly;
349354
350355 ArgumentGraph AG;
351356
357 Attributes::Builder B;
358 B.addAttribute(Attributes::NoCapture);
359
352360 // Check each function in turn, determining which pointer arguments are not
353361 // captured.
354362 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
370378 for (Function::arg_iterator A = F->arg_begin(), E = F->arg_end();
371379 A != E; ++A) {
372380 if (A->getType()->isPointerTy() && !A->hasNoCaptureAttr()) {
373 A->addAttr(Attribute::NoCapture);
381 A->addAttr(Attributes::get(B));
374382 ++NumNoCapture;
375383 Changed = true;
376384 }
385393 if (!Tracker.Captured) {
386394 if (Tracker.Uses.empty()) {
387395 // If it's trivially not captured, mark it nocapture now.
388 A->addAttr(Attribute::NoCapture);
396 A->addAttr(Attributes::get(B));
389397 ++NumNoCapture;
390398 Changed = true;
391399 } else {
418426 // eg. "void f(int* x) { if (...) f(x); }"
419427 if (ArgumentSCC[0]->Uses.size() == 1 &&
420428 ArgumentSCC[0]->Uses[0] == ArgumentSCC[0]) {
421 ArgumentSCC[0]->Definition->addAttr(Attribute::NoCapture);
429 ArgumentSCC[0]->Definition->addAttr(Attributes::get(B));
422430 ++NumNoCapture;
423431 Changed = true;
424432 }
460468
461469 for (unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
462470 Argument *A = ArgumentSCC[i]->Definition;
463 A->addAttr(Attribute::NoCapture);
471 A->addAttr(Attributes::get(B));
464472 ++NumNoCapture;
465473 Changed = true;
466474 }
20612061 }
20622062
20632063 static AttrListPtr StripNest(const AttrListPtr &Attrs) {
2064 Attributes::Builder B;
2065 B.addAttribute(Attributes::Nest);
2066
20642067 for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
20652068 if (!Attrs.getSlot(i).Attrs.hasAttribute(Attributes::Nest))
20662069 continue;
20672070
20682071 // There can be only one.
2069 return Attrs.removeAttr(Attrs.getSlot(i).Index, Attribute::Nest);
2072 return Attrs.removeAttr(Attrs.getSlot(i).Index, Attributes::get(B));
20702073 }
20712074
20722075 return Attrs;
21072110 Changed = true;
21082111 }
21092112
2110 if (F->getAttributes().hasAttrSomewhere(Attribute::Nest) &&
2113 if (F->getAttributes().hasAttrSomewhere(Attributes::Nest) &&
21112114 !F->hasAddressTaken()) {
21122115 // The function is not used by a trampoline intrinsic, so it is safe
21132116 // to remove the 'nest' attribute.
773773 // Conservatively require the attributes of the call to match those of the
774774 // return. Ignore noalias because it doesn't affect the call sequence.
775775 Attributes CalleeRetAttr = CS.getAttributes().getRetAttributes();
776 if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias)
776 if (Attributes::Builder(CalleeRetAttr ^ CallerRetAttr)
777 .removeAttribute(Attributes::NoAlias).hasAttributes())
777778 continue;
778779
779780 // Make sure the call instruction is followed by an unconditional branch to
635635 if (isa(EndPtr)) {
636636 // With a null EndPtr, this function won't capture the main argument.
637637 // It would be readonly too, except that it still may write to errno.
638 CI->addAttribute(1, Attribute::NoCapture);
638 Attributes::Builder B;
639 B.addAttribute(Attributes::NoCapture);
640 CI->addAttribute(1, Attributes::get(B));
639641 }
640642
641643 return 0;
237237 Bits &= ~A.Raw();
238238 }
239239
240 bool Attributes::Builder::hasAttribute(Attributes::AttrVal A) const {
241 return Bits & AttributesImpl::getAttrMask(A);
242 }
243
240244 bool Attributes::Builder::hasAttributes() const {
241245 return Bits != 0;
242246 }
252256 return 0;
253257 return 1U <<
254258 (((Bits & AttributesImpl::getAttrMask(Attributes::Alignment)) >> 16) - 1);
259 }
260
261 uint64_t Attributes::Builder::getStackAlignment() const {
262 if (!hasAlignmentAttr())
263 return 0;
264 return 1U <<
265 (((Bits & AttributesImpl::getAttrMask(Attributes::StackAlignment))>>26)-1);
255266 }
256267
257268 //===----------------------------------------------------------------------===//
467478
468479 /// hasAttrSomewhere - Return true if the specified attribute is set for at
469480 /// least one parameter or for the return value.
470 bool AttrListPtr::hasAttrSomewhere(Attributes Attr) const {
481 bool AttrListPtr::hasAttrSomewhere(Attributes::AttrVal Attr) const {
471482 if (AttrList == 0) return false;
472
483
473484 const SmallVector &Attrs = AttrList->Attrs;
474485 for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
475 if (Attrs[i].Attrs.hasAttributes(Attr))
486 if (Attrs[i].Attrs.hasAttribute(Attr))
476487 return true;
477488 return false;
478489 }