llvm.org GIT mirror llvm / f2e89e0
Make the 'get*AlignmentFromAttr' functions into member functions within the Attributes class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164308 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 8 years ago
5 changed file(s) with 34 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
204204 return Bits & Attribute::StackAlignment_i;
205205 }
206206
207 /// This returns the alignment field of an attribute as a byte alignment
208 /// value.
209 unsigned getAlignment() const {
210 if (!hasAlignmentAttr())
211 return 0;
212
213 return 1U << ((getRawAlignment() >> 16) - 1);
214 }
215
216 /// This returns the stack alignment field of an attribute as a byte alignment
217 /// value.
218 unsigned getStackAlignment() const {
219 if (!hasStackAlignmentAttr())
220 return 0;
221
222 return 1U << ((getRawStackAlignment() >> 26) - 1);
223 }
224
207225 // This is a "safe bool() operator".
208226 operator const void *() const { return Bits ? this : 0; }
209227 bool isEmptyOrSingleton() const { return (Bits & (Bits - 1)) == 0; }
211229 return Bits == Attrs.Bits;
212230 }
213231 bool operator != (const Attributes &Attrs) const {
214 return Bits != Attrs.Bits;
215 }
232 return !(this == Attrs);
233 }
234
216235 Attributes operator | (const Attributes &Attrs) const {
217236 return Attributes(Bits | Attrs.Bits);
218237 }
293312 return Attributes((Log2_32(i)+1) << 16);
294313 }
295314
296 /// This returns the alignment field of an attribute as a byte alignment value.
297 inline unsigned getAlignmentFromAttrs(Attributes A) {
298 if (!A.hasAlignmentAttr())
299 return 0;
300
301 return 1U << ((A.getRawAlignment() >> 16) - 1);
302 }
303
304315 /// This turns an int stack alignment (which must be a power of 2) into
305316 /// the form used internally in Attributes.
306317 inline Attributes constructStackAlignmentFromInt(unsigned i) {
311322 assert(isPowerOf2_32(i) && "Alignment must be a power of two.");
312323 assert(i <= 0x100 && "Alignment too large.");
313324 return Attributes((Log2_32(i)+1) << 26);
314 }
315
316 /// This returns the stack alignment field of an attribute as a byte alignment
317 /// value.
318 inline unsigned getStackAlignmentFromAttrs(Attributes A) {
319 if (!A.hasStackAlignmentAttr())
320 return 0;
321
322 return 1U << ((A.getRawStackAlignment() >> 26) - 1);
323325 }
324326
325327 /// This returns an integer containing an encoding of all the
449451 /// getParamAlignment - Return the alignment for the specified function
450452 /// parameter.
451453 unsigned getParamAlignment(unsigned Idx) const {
452 return Attribute::getAlignmentFromAttrs(getAttributes(Idx));
454 return getAttributes(Idx).getAlignment();
453455 }
454456
455457 /// hasAttrSomewhere - Return true if the specified attribute is set for at
27162716
27172717 // If the alignment was parsed as an attribute, move to the alignment field.
27182718 if (FuncAttrs & Attribute::Alignment) {
2719 Alignment = Attribute::getAlignmentFromAttrs(FuncAttrs);
2719 Alignment = FuncAttrs.getAlignment();
27202720 FuncAttrs &= ~Attribute::Alignment;
27212721 }
27222722
5959 MFInfo = 0;
6060 FrameInfo = new (Allocator) MachineFrameInfo(*TM.getFrameLowering());
6161 if (Fn->hasFnAttr(Attribute::StackAlignment))
62 FrameInfo->ensureMaxAlignment(Attribute::getStackAlignmentFromAttrs(
63 Fn->getAttributes().getFnAttributes()));
62 FrameInfo->ensureMaxAlignment(Fn->getAttributes().
63 getFnAttributes().getStackAlignment());
6464 ConstantPool = new (Allocator) MachineConstantPool(TM.getTargetData());
6565 Alignment = TM.getTargetLowering()->getMinFunctionAlignment();
6666 // FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
507507 #undef HANDLE_ATTR
508508 if (attrs & Attribute::StackAlignment)
509509 Out << " | Attribute::constructStackAlignmentFromInt("
510 << Attribute::getStackAlignmentFromAttrs(attrs)
510 << attrs.getStackAlignment()
511511 << ")";
512512 attrs &= ~Attribute::StackAlignment;
513513 assert(attrs == 0 && "Unhandled attribute!");
7979 Result += "address_safety ";
8080 if (hasStackAlignmentAttr()) {
8181 Result += "alignstack(";
82 Result += utostr(Attribute::getStackAlignmentFromAttrs(*this));
82 Result += utostr(getStackAlignment());
8383 Result += ") ";
8484 }
8585 if (hasAlignmentAttr()) {
8686 Result += "align ";
87 Result += utostr(Attribute::getAlignmentFromAttrs(*this));
87 Result += utostr(getAlignment());
8888 Result += " ";
8989 }
9090 // Trim the trailing space.
173173
174174 #ifndef NDEBUG
175175 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
176 assert(Attrs[i].Attrs != Attribute::None &&
176 assert(Attrs[i].Attrs.hasAttributes() &&
177177 "Pointless attribute!");
178178 assert((!i || Attrs[i-1].Index < Attrs[i].Index) &&
179179 "Misordered AttributesList!");
246246 /// returned. Attributes for the result are denoted with Idx = 0.
247247 /// Function notes are denoted with idx = ~0.
248248 Attributes AttrListPtr::getAttributes(unsigned Idx) const {
249 if (AttrList == 0) return Attribute::None;
249 if (AttrList == 0) return Attributes();
250250
251251 const SmallVector &Attrs = AttrList->Attrs;
252252 for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i)
253253 if (Attrs[i].Index == Idx)
254254 return Attrs[i].Attrs;
255 return Attribute::None;
255
256 return Attributes();
256257 }
257258
258259 /// hasAttrSomewhere - Return true if the specified attribute is set for at
273274 #ifndef NDEBUG
274275 // FIXME it is not obvious how this should work for alignment.
275276 // For now, say we can't change a known alignment.
276 unsigned OldAlign = Attribute::getAlignmentFromAttrs(OldAttrs);
277 unsigned NewAlign = Attribute::getAlignmentFromAttrs(Attrs);
277 unsigned OldAlign = OldAttrs.getAlignment();
278 unsigned NewAlign = Attrs.getAlignment();
278279 assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
279280 "Attempt to change alignment!");
280281 #endif