llvm.org GIT mirror llvm / 672893c
[Alignment][NFC] Attributes use Align/MaybeAlign Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69278 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375495 91177308-0d34-0410-b5e6-96231b3b80d8 Guillaume Chatelet 1 year, 6 days ago
7 changed file(s) with 78 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
150150
151151 /// Returns the alignment field of an attribute as a byte alignment
152152 /// value.
153 unsigned getAlignment() const;
153 MaybeAlign getAlignment() const;
154154
155155 /// Returns the stack alignment field of an attribute as a byte
156156 /// alignment value.
157 unsigned getStackAlignment() const;
157 MaybeAlign getStackAlignment() const;
158158
159159 /// Returns the number of dereferenceable bytes from the
160160 /// dereferenceable attribute.
284284 /// Return the target-dependent attribute object.
285285 Attribute getAttribute(StringRef Kind) const;
286286
287 unsigned getAlignment() const;
288 unsigned getStackAlignment() const;
287 MaybeAlign getAlignment() const;
288 MaybeAlign getStackAlignment() const;
289289 uint64_t getDereferenceableBytes() const;
290290 uint64_t getDereferenceableOrNullBytes() const;
291291 Type *getByValType() const;
603603 }
604604
605605 /// Return the alignment of the return value.
606 unsigned getRetAlignment() const;
606 MaybeAlign getRetAlignment() const;
607607
608608 /// Return the alignment for the specified function parameter.
609 unsigned getParamAlignment(unsigned ArgNo) const;
609 MaybeAlign getParamAlignment(unsigned ArgNo) const;
610610
611611 /// Return the byval type for the specified function parameter.
612612 Type *getParamByValType(unsigned ArgNo) const;
613613
614614 /// Get the stack alignment.
615 unsigned getStackAlignment(unsigned Index) const;
615 MaybeAlign getStackAlignment(unsigned Index) const;
616616
617617 /// Get the number of dereferenceable bytes (or zero if unknown).
618618 uint64_t getDereferenceableBytes(unsigned Index) const;
795795 /// doesn't exist, pair(0, 0) is returned.
796796 std::pair> getAllocSizeArgs() const;
797797
798 /// This turns an alignment into the form used internally in Attribute.
799 /// This call has no effect if Align is not set.
800 AttrBuilder &addAlignmentAttr(MaybeAlign Align);
801
798802 /// This turns an int alignment (which must be a power of 2) into the
799803 /// form used internally in Attribute.
800 AttrBuilder &addAlignmentAttr(unsigned Align);
804 /// This call has no effect if Align is 0.
805 /// Deprecated, use the version using a MaybeAlign.
806 inline AttrBuilder &addAlignmentAttr(unsigned Align) {
807 return addAlignmentAttr(MaybeAlign(Align));
808 }
809
810 /// This turns a stack alignment into the form used internally in Attribute.
811 /// This call has no effect if Align is not set.
812 AttrBuilder &addStackAlignmentAttr(MaybeAlign Align);
801813
802814 /// This turns an int stack alignment (which must be a power of 2) into
803815 /// the form used internally in Attribute.
804 AttrBuilder &addStackAlignmentAttr(unsigned Align);
816 /// This call has no effect if Align is 0.
817 /// Deprecated, use the version using a MaybeAlign.
818 inline AttrBuilder &addStackAlignmentAttr(unsigned Align) {
819 return addStackAlignmentAttr(MaybeAlign(Align));
820 }
805821
806822 /// This turns the number of dereferenceable bytes into the form used
807823 /// internally in Attribute.
342342 unsigned getFnStackAlignment() const {
343343 if (!hasFnAttribute(Attribute::StackAlignment))
344344 return 0;
345 return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
345 if (const auto MA =
346 AttributeSets.getStackAlignment(AttributeList::FunctionIndex))
347 return MA->value();
348 return 0;
346349 }
347350
348351 /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
432435
433436 /// Extract the alignment for a call or parameter (0=unknown).
434437 unsigned getParamAlignment(unsigned ArgNo) const {
435 return AttributeSets.getParamAlignment(ArgNo);
438 if (const auto MA = AttributeSets.getParamAlignment(ArgNo))
439 return MA->value();
440 return 0;
436441 }
437442
438443 /// Extract the byval type for a parameter.
15661566 }
15671567
15681568 /// Extract the alignment of the return value.
1569 unsigned getRetAlignment() const { return Attrs.getRetAlignment(); }
1569 unsigned getRetAlignment() const {
1570 if (const auto MA = Attrs.getRetAlignment())
1571 return MA->value();
1572 return 0;
1573 }
15701574
15711575 /// Extract the alignment for a call or parameter (0=unknown).
15721576 unsigned getParamAlignment(unsigned ArgNo) const {
1573 return Attrs.getParamAlignment(ArgNo);
1577 if (const auto MA = Attrs.getParamAlignment(ArgNo))
1578 return MA->value();
1579 return 0;
15741580 }
15751581
15761582 /// Extract the byval type for a call or parameter.
207207 Attribute getAttribute(Attribute::AttrKind Kind) const;
208208 Attribute getAttribute(StringRef Kind) const;
209209
210 unsigned getAlignment() const;
211 unsigned getStackAlignment() const;
210 MaybeAlign getAlignment() const;
211 MaybeAlign getStackAlignment() const;
212212 uint64_t getDereferenceableBytes() const;
213213 uint64_t getDereferenceableOrNullBytes() const;
214214 std::pair> getAllocSizeArgs() const;
240240 return pImpl && pImpl->hasAttribute(Kind);
241241 }
242242
243 unsigned Attribute::getAlignment() const {
243 MaybeAlign Attribute::getAlignment() const {
244244 assert(hasAttribute(Attribute::Alignment) &&
245245 "Trying to get alignment from non-alignment attribute!");
246 return pImpl->getValueAsInt();
247 }
248
249 unsigned Attribute::getStackAlignment() const {
246 return MaybeAlign(pImpl->getValueAsInt());
247 }
248
249 MaybeAlign Attribute::getStackAlignment() const {
250250 assert(hasAttribute(Attribute::StackAlignment) &&
251251 "Trying to get alignment from non-alignment attribute!");
252 return pImpl->getValueAsInt();
252 return MaybeAlign(pImpl->getValueAsInt());
253253 }
254254
255255 uint64_t Attribute::getDereferenceableBytes() const {
666666 return SetNode ? SetNode->getAttribute(Kind) : Attribute();
667667 }
668668
669 unsigned AttributeSet::getAlignment() const {
670 return SetNode ? SetNode->getAlignment() : 0;
671 }
672
673 unsigned AttributeSet::getStackAlignment() const {
674 return SetNode ? SetNode->getStackAlignment() : 0;
669 MaybeAlign AttributeSet::getAlignment() const {
670 return SetNode ? SetNode->getAlignment() : None;
671 }
672
673 MaybeAlign AttributeSet::getStackAlignment() const {
674 return SetNode ? SetNode->getStackAlignment() : None;
675675 }
676676
677677 uint64_t AttributeSet::getDereferenceableBytes() const {
832832 return {};
833833 }
834834
835 unsigned AttributeSetNode::getAlignment() const {
835 MaybeAlign AttributeSetNode::getAlignment() const {
836836 for (const auto I : *this)
837837 if (I.hasAttribute(Attribute::Alignment))
838838 return I.getAlignment();
839 return 0;
840 }
841
842 unsigned AttributeSetNode::getStackAlignment() const {
839 return None;
840 }
841
842 MaybeAlign AttributeSetNode::getStackAlignment() const {
843843 for (const auto I : *this)
844844 if (I.hasAttribute(Attribute::StackAlignment))
845845 return I.getStackAlignment();
846 return 0;
846 return None;
847847 }
848848
849849 Type *AttributeSetNode::getByValType() const {
11601160 #ifndef NDEBUG
11611161 // FIXME it is not obvious how this should work for alignment. For now, say
11621162 // we can't change a known alignment.
1163 unsigned OldAlign = getAttributes(Index).getAlignment();
1163 const MaybeAlign OldAlign = getAttributes(Index).getAlignment();
11641164 unsigned NewAlign = B.getAlignment();
11651165 assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
11661166 "Attempt to change alignment!");
13451345 return getAttributes(Index).getAttribute(Kind);
13461346 }
13471347
1348 unsigned AttributeList::getRetAlignment() const {
1348 MaybeAlign AttributeList::getRetAlignment() const {
13491349 return getAttributes(ReturnIndex).getAlignment();
13501350 }
13511351
1352 unsigned AttributeList::getParamAlignment(unsigned ArgNo) const {
1352 MaybeAlign AttributeList::getParamAlignment(unsigned ArgNo) const {
13531353 return getAttributes(ArgNo + FirstArgIndex).getAlignment();
13541354 }
13551355
13571357 return getAttributes(Index+FirstArgIndex).getByValType();
13581358 }
13591359
1360
1361 unsigned AttributeList::getStackAlignment(unsigned Index) const {
1360 MaybeAlign AttributeList::getStackAlignment(unsigned Index) const {
13621361 return getAttributes(Index).getStackAlignment();
13631362 }
13641363
15151514 return unpackAllocSizeArgs(AllocSizeArgs);
15161515 }
15171516
1518 AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned A) {
1519 MaybeAlign Align(A);
1517 AttrBuilder &AttrBuilder::addAlignmentAttr(MaybeAlign Align) {
15201518 if (!Align)
15211519 return *this;
15221520
15271525 return *this;
15281526 }
15291527
1530 AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned A) {
1531 MaybeAlign Align(A);
1528 AttrBuilder &AttrBuilder::addStackAlignmentAttr(MaybeAlign Align) {
15321529 // Default alignment, allow the target to define how to align it.
15331530 if (!Align)
15341531 return *this;
14721472 // Just print .param .align .b8 .param[size];
14731473 // = PAL.getparamalignment
14741474 // size = typeallocsize of element type
1475 unsigned align = PAL.getParamAlignment(paramIndex);
1476 if (align == 0)
1477 align = DL.getABITypeAlignment(Ty);
1475 const Align align = DL.getValueOrABITypeAlignment(
1476 PAL.getParamAlignment(paramIndex), Ty);
14781477
14791478 unsigned sz = DL.getTypeAllocSize(Ty);
1480 O << "\t.param .align " << align << " .b8 ";
1479 O << "\t.param .align " << align.value() << " .b8 ";
14811480 printParamName(I, paramIndex, O);
14821481 O << "[" << sz << "]";
14831482
15581557 // Just print .param .align .b8 .param[size];
15591558 // = PAL.getparamalignment
15601559 // size = typeallocsize of element type
1561 unsigned align = PAL.getParamAlignment(paramIndex);
1562 if (align == 0)
1563 align = DL.getABITypeAlignment(ETy);
1560 Align align =
1561 DL.getValueOrABITypeAlignment(PAL.getParamAlignment(paramIndex), ETy);
15641562 // Work around a bug in ptxas. When PTX code takes address of
15651563 // byval parameter with alignment < 4, ptxas generates code to
15661564 // spill argument into memory. Alas on sm_50+ ptxas generates
15721570 // TODO: this will need to be undone when we get to support multi-TU
15731571 // device-side compilation as it breaks ABI compatibility with nvcc.
15741572 // Hopefully ptxas bug is fixed by then.
1575 if (!isKernelFunc && align < 4)
1576 align = 4;
1573 if (!isKernelFunc && align < Align(4))
1574 align = Align(4);
15771575 unsigned sz = DL.getTypeAllocSize(ETy);
1578 O << "\t.param .align " << align << " .b8 ";
1576 O << "\t.param .align " << align.value() << " .b8 ";
15791577 printParamName(I, paramIndex, O);
15801578 O << "[" << sz << "]";
15811579 continue;
143143 Attribute::getWithAlignment(C, Align(8)));
144144 AL = AL.addAttribute(C, AttributeList::FirstArgIndex + 1,
145145 Attribute::getWithAlignment(C, Align(32)));
146 EXPECT_EQ(8U, AL.getParamAlignment(0));
147 EXPECT_EQ(32U, AL.getParamAlignment(1));
146 EXPECT_EQ(Align(8), AL.getParamAlignment(0));
147 EXPECT_EQ(Align(32), AL.getParamAlignment(1));
148148
149149 AttrBuilder B;
150150 B.addAttribute(Attribute::NonNull);
151151 B.addAlignmentAttr(8);
152152 AL = AL.addAttributes(C, AttributeList::FirstArgIndex, B);
153 EXPECT_EQ(8U, AL.getParamAlignment(0));
154 EXPECT_EQ(32U, AL.getParamAlignment(1));
153 EXPECT_EQ(Align(8), AL.getParamAlignment(0));
154 EXPECT_EQ(Align(32), AL.getParamAlignment(1));
155155 EXPECT_TRUE(AL.hasParamAttribute(0, Attribute::NonNull));
156156 }
157157